public final class DefaultExecutors extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
ensureShutdown(ExecutorService executor,
Duration timeoutBeforeForcefulShutdown)
Perform an orderly shutdown, trying to wait for any currently running tasks to finish,
or else forcefully shutdown the executor if the tasks are not able to finish their work
within the given timeout duration.
|
static void |
ensureShutdown(String executorName,
ExecutorService executor,
Duration timeoutBeforeForcefulShutdown)
Perform an orderly shutdown, trying to wait for any currently running tasks to finish,
or else forcefully shutdown the executor if the tasks are not able to finish their work
within the given timeout duration.
|
static ExecutorService |
externallyManaged(ExecutorService executor)
Wraps another
ExecutorService as an "externally managed
executor service", which will discard any invocations of the
methods used to manage the lifecycle of the ExecutorService itself. |
static ExecutorService |
fixedThreadPool(int threadAmount,
String name) |
static boolean |
isExternallyManaged(ExecutorService executor)
Determine if the given
ExecutorService is marked as
externally managed. |
static ExecutorService |
singleThreaded(String name) |
static ThreadFactory |
threadNamingFactory(LongFunction<String> threadName) |
static ThreadFactory |
threadNamingFactory(LongFunction<String> threadName,
ThreadFactory backingFactory) |
public static ExecutorService fixedThreadPool(int threadAmount, String name)
public static ExecutorService singleThreaded(String name)
public static ThreadFactory threadNamingFactory(LongFunction<String> threadName)
public static ThreadFactory threadNamingFactory(LongFunction<String> threadName, ThreadFactory backingFactory)
public static ExecutorService externallyManaged(ExecutorService executor)
ExecutorService as an "externally managed
executor service", which will discard any invocations of the
methods used to manage the lifecycle of the ExecutorService itself.
This includes the methods:
ExecutorService.shutdown()ExecutorService.shutdownNow() (returns empty list)ExecutorService.awaitTermination(long, TimeUnit) (immediately
returns with the result of ExecutorService.isTerminated())ensureShutdown(ExecutorService, Duration).public static boolean isExternallyManaged(ExecutorService executor)
ExecutorService is marked as
externally managed.public static void ensureShutdown(ExecutorService executor, Duration timeoutBeforeForcefulShutdown)
ensureShutdown(String, ExecutorService, Duration)
method is preferred over this.executor - the ExecutorService to shut down.timeoutBeforeForcefulShutdown - the maximum amount of time to wait for tasks to finish
before forcefully shutting down the executor.public static void ensureShutdown(String executorName, ExecutorService executor, Duration timeoutBeforeForcefulShutdown)
executorName - a descriptive name of the executor to shut down, used for logging.executor - the ExecutorService to shut down.timeoutBeforeForcefulShutdown - the maximum amount of time to wait for tasks to finish
before forcefully shutting down the executor.Copyright © 2016 Digipost. All rights reserved.