日期:2014-05-17 浏览次数:20724 次
public class TestThread implements Runnable {
public Serverproxy serverproxy;
private TestITDSDownload ts;
public TestThread(Serverproxy serverproxy,TestITDSDownload tsd) {
this.serverproxy = serverproxy;
this.ts=tsd;
}
public void run() {
try {
int result=ts.getITDSStatus(serverproxy.getIp(),
serrverproxy.getFileId());//下载的方法会返回一个int类型判断是否下载成功
if(result==1)
{serverproxy.setResult("下载成功");}
if(result==2)
{serverproxy.setResult("下载失败");}
if(result==4)
{serverproxy.setResult("内部错误");} System.out.println("serverproxyResult:"+serverproxy.getIp()+serverproxy.getResult());
System.out.println("size为:"+TestITDSDownload.getSize());
System.out.println("结果添加前的serverproxyCheckList的长度:"+ts.serverproxyCheckList.size());
ts.serverproxyCheckList.add(serverproxy);
System.out.println("结果添加后的serverproxyCheckList的长度:"+ts.serverproxyCheckList.size());
System.out.println("现在的isSuccess为:"+ts.getSuccess());
if(ts.serverproxyCheckList.size()==TestITDSDownload.getSize()){
ts.setSuccess(true);
System.out.println("相等,isSuccess为:"+ts.getSuccess());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
}
public class TestITDSDownload {
public List<Serverproxy> serverproxyCheckList = new ArrayList<Serverproxy>();
public boolean isSuccess=false;
public boolean getSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
//..其他代码
//开启线程的方法
public List<Serverproxy> check(List<Serverproxy> serverproxyList) throws Exception {
TestITDSDownload.setSize(serverproxyList.size());
for (int i = 0; i < serverproxyList.size(); i++) {
TestThread t = new TestThread(serverproxyList.get(i),this);
Thread thread = new Thread(t);
thread.start();
}
while(true){
if(getSuccess()){
System.out.println("成功!当前isSuccess为:"+getSuccess());
break;
}
}
return serverproxyCheckList;