正如標題所顯示,如果的Future.get(超時)超時,併線程繼續運行,是否線程繼續運行時的Future.get(超時)超時
ExecutorService executor = Executors.newFixedThreadPool(n);
Callable<Object> task = new Callable<Object>() {
public Object call() {
//...
}
}
Future<Object> future = executor.submit(task);
try {
Object result = future.get(5, TimeUnit.SECONDS);
} catch (TimeoutException ex) {
// handle the timeout
}
如果線程繼續運行,由於某些IO等原因而被阻塞,那麼當線程池變滿時,不能新任務被獲取,這意味着trheadpool會被卡住,因爲池中的所有線程都被阻塞了,對嗎?
你試過添加一些I/O來看看會發生什麼嗎? – 2010-12-08 10:07:49