public final class ExecutorCloser extends Object implements Closeable
Utility class to properly close any ExecutorService.
It will attempt a graceful close within the provided timeout. If after such any of the contained tasks are not terminated yet, it will force a shutdown and track a warning in the logs.
| Constructor and Description |
|---|
ExecutorCloser(ExecutorService executorService)
will attempt a graceful close in 5 seconds
|
ExecutorCloser(ExecutorService executorService,
int timeout,
TimeUnit unit)
will attempt a graceful close by the provided time.
|
public ExecutorCloser(@Nullable ExecutorService executorService)
executorService - public ExecutorCloser(@Nullable ExecutorService executorService, int timeout, TimeUnit unit)
executorService - the executor to closetimeout - the time to wait forunit - the unit of timepublic void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2012-2019 The Apache Software Foundation. All Rights Reserved.