-4
我有4個線程正在運行,並且運行增加了全局數組列表的大小。但是在線程完成後無法訪問所得到的數組列表。有沒有一種方法可以訪問所得到的數組列表,或者它如何與線程一起工作並回收數據結構?如何在4個線程完成後訪問數組列表
List<MyObject> head = a.subList(0, 2000);
List<MyObject> body = a.subList(2001, 5000);
List<MyObject> body2 = a.subList(5001, 8000);
List<MyObject> tail = a.subList(8001, a.size());
//System.out.println(tail.size());
createAndRunFirst(head);
createAndRunFirst(body);
這些都是調用
,這是被稱爲4 times..and我需要的currCDO arrylist
public void algo(List<MyObject>list){
MyObject a = null;
MyObject b = null;
int e=0;
String curr1="";
String curr2="";
for (int i = 0; i < list.size(); i++) {
a =list.get(i);
curr1= a.getStreetName();
if(curr1.contains("-")){
curr1=curr1.replace("-", " ");
}
if(curr1.contains("STRASSE")){
curr1=curr1.replace("STRASSE", "STR.");
}
else{
curr1=a.getStreetName();
}
for (int j = 0; j < lotse.size(); j++) {
b = lotse.get(j);
curr2=b.getStreetName();
if(curr2.contains("-")){
curr2=curr2.replace("-", " ");
}
if(curr2.contains("STRASSE")){
curr2=curr2.replace("STRASSE", "STR.");
}
else{
curr2=b.getStreetName();
}
int d = dL.execute(curr1,curr2);
if(curr1.length()==curr2.length()){
e=0;
}
if(curr1.length()< curr2.length()){
e=(curr2.length()*30)/100;
//System.out.println(d);
}
if(curr1.length()> curr2.length()){
e=(curr1.length()*30)/100;
//System.out.println(d);
}
if(d<e && a.getPcode().contains(b.getPcode())){
int x=a.getInstituteName().length();
int y=b.getInstituteName().length();
if(x<y){
currCDO.add(a);
}
if(y<x){
currCDO.add(a);
if(x==y){
currCDO.add(a);
}
break;}else{
//System.out.println(a.getInstituteName()+"******");
restCDO.add(a);
}
}//System.out.println(currCDO.size() +"*****");
}
}
}
public void createAndRunFirst(final List<CrawlerDataObject> list) {
Thread thread = new Thread(new Runnable() {
@Override
public void run(){
algo(list);
}
});
thread.start();
}
請添加一些代碼?你有什麼嘗試?我們不知道如何解決你的問題,如果我們甚至不知道什麼代碼導致它 – DankMemes
換句話說,...你說,「我不能訪問由此產生的數組列表。你如何知道你無法訪問它?你的代碼試圖訪問它的地方在哪裏?你期望它做什麼(最好是,你期望它打印什麼)?它實際上做了什麼/打印呢? –
subList創建淺表副本,因此對每個子列表中的對象所做的更改應顯示爲主列表 – DankMemes