blob: 33588ffe3f77f542eceffe01fe57fd925f8d2d61 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package derms.util;
import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
public class ThreadPool {
public static final Duration timeout = Duration.ofSeconds(1);
public static void shutDown(ExecutorService pool, Logger log) {
pool.shutdownNow();
try {
if (!pool.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS))
log.warning("Thread pool did not terminate after " + timeout);
} catch (InterruptedException e) {
log.warning("Interrupted while terminating thread pool: " + e.getMessage());
// Preserve interrupt status.
Thread.currentThread().interrupt();
}
}
}
|