-1
要調用一個Web服務中的一個線索,需要設定一個時間限制來執行線程 和需要的任何實例執行返回值成功,失敗ids 像t.start();和t.stop();在時間內
要調用一個Web服務中的一個線索,需要設定一個時間限制來執行線程 和需要的任何實例執行返回值成功,失敗ids 像t.start();和t.stop();在時間內
Future<T> result = Executors.newSingleThreadScheduledExecutor().submit(
new Callable<T>() {
@Override
public void run() {
//perform action here
while(!Thread.interrupted()){
//do next stage of calculation
}
}
});
T value = result.get(10, TimeUnit.SECONDS); //for example wait 10 seconds
if(value == null) {
//process is not finished
result.cancel(true); //interrupt task
}
Web服務調用是原子操作,它不會返回部分結果,除非它被設計爲這樣做。例如,接受請求並開始處理的Web服務,以及第二次服務調用會中斷操作並請求部分結果。