0
if (isDownloadLogRequired) {
ExecutorService pool = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
for (HostGenericServiceTicket hostGenericServiceTicket : hostGenericServiceTickets) {
pool.submit(new DiagnosticLogDownloader(logNames, downloadTo, hostGenericServiceTicket));
}
pool.shutdown();
try {
pool.awaitTermination(downloadTimeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.err.println(MessageFormat.format("{0}: Reason: {1}", e.getClass()
.getSimpleName(), e.getMessage()));
}
}
如果downloadTimeout設置爲180秒線程應該被終止並且程序應該正確結束?await在線程池終結並不會終止線程池
不過,爲什麼是這個樣子這個API的說明? - 布爾awaitTermination(長超時, TIMEUNIT單元) 拋出InterruptedException的 \t阻塞,直到所有任務已經完成了關機請求之後執行,或在超時 \t發生時,或當前線程中斷,無論哪個首先發生。 – Manav
是的,這正是我所說的「以先發生者爲準」。它實際上並沒有做任何事情來終止線程。 –
那麼程序應該在超時之後向前移動,並且結束正確的時間?......它應該只阻止超時量秒,然後應該向前移動......並且當程序死亡時,所有線程都應該死掉。 。我的意思是,在我的情況下,超時發生在第一位......所以代碼在這次調用中沒有更多的阻止,並向前移動? – Manav