我想運行兩個runnables一個接一個線程。android運行多個可運行
這意味着當第一個可運行線程完成第二個線程啓動時。
DownSpeedTester speedTester = new DownSpeedTester();
speedTester.setDownUrl(String.valueOf(urlDownload));
new Thread(speedTester).start();
UploadSpeedTester uploadSpeedTester = new UploadSpeedTester();
uploadSpeedTester.setUploadUrl(String.valueOf(urlUpload));
new Thread(uploadSpeedTester).start();
嘗試使用newSingleThreadExecutor,但它沒有成功。
ExecutorService es = Executors.newSingleThreadExecutor();
Future< Boolean> result = es.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
//Download
DownSpeedTester speedTester = new DownSpeedTester();
speedTester.setDownUrl(String.valueOf(urlDownload));
new Thread(speedTester).start();
return true;
}
});
try {
boolean res = result.get();
if (res == true){
//Upload
Log.d("mceeli","UploadSpeedTester");
UploadSpeedTester uploadSpeedTester = new UploadSpeedTester();
uploadSpeedTester.setUploadUrl(String.valueOf(urlUpload));
new Thread(uploadSpeedTester).start();
}
} catch (Exception e) {
}
es.shutdown();
它仍然在一起運行。
請幫幫我。
在第一個回調中調用第二個線程 – Amy