@ParametersAreNonnullByDefault public final class MoreExecutors extends Object
Executor instances.| Modifier and Type | Method and Description |
|---|---|
static ExecutorService |
newDirectPool()
Creates a new
ExecutorService that runs each task in the thread that invokes execute/submit. |
static ExecutorService |
newFixedThreadPool()
Creates a new
ExecutorService using the maximum available
processors, that will be closed when the application will exit. |
static ExecutorService |
newFixedThreadPool(int nThreads)
Creates a new
ExecutorService using nThreads processors, that will be closed when the application
will exit. |
static ExecutorService |
newFixedThreadPool(int nThreads,
String name)
Creates a new
ExecutorService using nThreads processors, that will be closed when the application
will exit. |
static ExecutorService |
newFixedThreadPool(String name)
Creates a new
ExecutorService using the maximum available
processors, that will be closed when the application will exit. |
static List<Runnable> |
shutdown(ExecutorService service,
long timeout,
TimeUnit unit)
Cleanly closes the
service. |
static void |
shutdown(ExecutorService service,
long timeout,
TimeUnit unit,
boolean executeUnstarted)
Cleanly closes the
service. |
static ExecutorService |
shutdownAtExit(ExecutorService service,
long timeout,
TimeUnit unit,
boolean executeUnstarted)
Adds a shutdown hook to cleanly closes the
service when the application will exit. |
@Nonnull public static ExecutorService newDirectPool()
ExecutorService that runs each task in the thread that invokes execute/submit. This
applies both to individually submitted tasks and to collections of tasks submitted via invokeAll or
invokeAny. In the latter case, tasks will run serially on the calling thread. Tasks are run to completion
before a Future is returned to the caller (unless the executor has been shutdown).
Although all tasks are immediately executed in the thread that submitted the task, this ExecutorService
imposes a small locking overhead on each task submission in order to implement shutdown and termination
behavior.
@Nonnull public static ExecutorService newFixedThreadPool()
ExecutorService using the maximum available
processors, that will be closed when the application will exit.IllegalArgumentException - if nThreads <= 0newFixedThreadPool(int)@Nonnull public static ExecutorService newFixedThreadPool(String name)
ExecutorService using the maximum available
processors, that will be closed when the application will exit.IllegalArgumentException - if nThreads <= 0newFixedThreadPool(int)@Nonnull public static ExecutorService newFixedThreadPool(int nThreads)
ExecutorService using nThreads processors, that will be closed when the application
will exit.nThreads - the number of threads in the poolIllegalArgumentException - if nThreads <= 0newFixedThreadPool(int, String)@Nonnull public static ExecutorService newFixedThreadPool(int nThreads, @Nullable String name)
ExecutorService using nThreads processors, that will be closed when the application
will exit.nThreads - the number of threads in the poolname - the name of the poolIllegalArgumentException - if nThreads <= 0Executors.newFixedThreadPool(int),
MoreThreads.newThreadFactory(),
shutdownAtExit(ExecutorService, long, TimeUnit, boolean)public static void shutdown(ExecutorService service, long timeout, TimeUnit unit, boolean executeUnstarted)
service.service - the service to closetimeout - the maximum time to waitunit - the time unit of the timeout argumentexecuteUnstarted - true if the remaining tasks must be executed synchronously if they have not
completed their execution after the shutdown requestNullPointerException - if any argument is nullIllegalArgumentException - if timeout < 0ExecutorService.shutdown(),
ExecutorService.awaitTermination(long, TimeUnit),
ExecutorService.shutdownNow()@Nonnull public static List<Runnable> shutdown(ExecutorService service, long timeout, TimeUnit unit)
service.service - the service to closetimeout - the maximum time to waitunit - the time unit of the timeout argumentNullPointerException - if any argument is nullIllegalArgumentException - if timeout < 0ExecutorService.shutdown(),
ExecutorService.awaitTermination(long, TimeUnit),
ExecutorService.shutdownNow()@Nonnull public static ExecutorService shutdownAtExit(ExecutorService service, long timeout, TimeUnit unit, boolean executeUnstarted)
service when the application will exit.service - the service to closetimeout - the maximum time to waitunit - the time unit of the timeout argumentexecuteUnstarted - true if the remaining tasks must be executed synchronously if they have not
completed their execution after the shutdown requestserviceNullPointerException - if any argument is nullIllegalArgumentException - if timeout < 0ExecutorService.shutdown(),
ExecutorService.awaitTermination(long, TimeUnit),
ExecutorService.shutdownNow()Copyright © 2017–2019 Atlanmod. All rights reserved.