Package dev.enola.common.concurrent
Class Executors
java.lang.Object
dev.enola.common.concurrent.Executors
Additional factory and utility methods for executors.
Use this instead of Executors, because it ensures that:
- the
TLCis correctly propagated - the returned Executor uses a
ThreadFactorythat is named, - has an UncaughtExceptionHandler which logs to SLF4j
- can return (Guava's) ListenableFuture.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecutorServicenewCachedThreadPool(String namePrefix, org.slf4j.Logger logger) static ExecutorServicenewFixedThreadPool(int size, String namePrefix, org.slf4j.Logger logger) static ListeningExecutorServicenewListeningCachedThreadPool(String namePrefix, org.slf4j.Logger logger) static ListeningExecutorServiceCreates an executor service that runs each task in the thread that invokes execute/submit.static ListeningExecutorServicenewListeningFixedThreadPool(int size, String namePrefix, org.slf4j.Logger logger) newListeningScheduledThreadPool(int corePoolSize, String namePrefix, org.slf4j.Logger logger) static ListeningExecutorServicenewListeningSingleThreadExecutor(String namePrefix, org.slf4j.Logger logger) Creates a single thread executor with aThreadFactorythat uses the provided prefix for its thread names and logs uncaught exceptions with the specifiedLogger.newListeningSingleThreadScheduledExecutor(String namePrefix, org.slf4j.Logger logger) static ExecutorServicenewSingleThreadExecutor(String namePrefix, org.slf4j.Logger logger) static voidshutdownAndAwaitTermination(ExecutorService executorService)
-
Field Details
-
DEFAULT_TIMEOUT_FOR_SHUTDOWN
- See Also:
-
DEFAULT_TIMEOUT_UNIT_FOR_SHUTDOWN
-
-
Method Details
-
newListeningDirectExecutor
Creates an executor service that runs each task in the thread that invokes execute/submit. This does not take namePrefix and Logger arguments, to make it clear they are not needed, because no separate new threads will ever be created. Note that a "scheduled direct Executor" variant doesn't really make sense conceptually (unless you would want it to just completely ignore all requested delays; which would be weird).- See Also:
-
newListeningSingleThreadExecutor
public static ListeningExecutorService newListeningSingleThreadExecutor(String namePrefix, org.slf4j.Logger logger) Creates a single thread executor with aThreadFactorythat uses the provided prefix for its thread names and logs uncaught exceptions with the specifiedLogger.- Parameters:
namePrefix- Prefix for threads from this executor. For example, "rpc-pool", to create "rpc-pool-1/2/3" named threads. Note that this is a prefix, not a format, so you pass just "rpc-pool" instead of e.g. "rpc-pool-%d".logger- Logger used to log uncaught exceptions from new threads created from this.- See Also:
-
newSingleThreadExecutor
-
newListeningFixedThreadPool
public static ListeningExecutorService newListeningFixedThreadPool(int size, String namePrefix, org.slf4j.Logger logger) - See Also:
-
newFixedThreadPool
public static ExecutorService newFixedThreadPool(int size, String namePrefix, org.slf4j.Logger logger) -
newListeningCachedThreadPool
public static ListeningExecutorService newListeningCachedThreadPool(String namePrefix, org.slf4j.Logger logger) - See Also:
-
newCachedThreadPool
-
newListeningSingleThreadScheduledExecutor
public static ListeningScheduledExecutorService newListeningSingleThreadScheduledExecutor(String namePrefix, org.slf4j.Logger logger) - See Also:
-
newListeningScheduledThreadPool
public static ListeningScheduledExecutorService newListeningScheduledThreadPool(int corePoolSize, String namePrefix, org.slf4j.Logger logger) - See Also:
-
shutdownAndAwaitTermination
-