Package no.digipost
Class DiggConcurrent
java.lang.Object
no.digipost.DiggConcurrent
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidensureShutdown(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 voidensureShutdown(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 ExecutorServiceexternallyManaged(ExecutorService executor) Wraps anotherExecutorServiceas an "externally managed executor service", which will discard any invocations of the methods used to manage the lifecycle of the ExecutorService itself.static ExecutorServicefixedThreadPool(int threadAmount, String name) static booleanisExternallyManaged(ExecutorService executor) Determine if the givenExecutorServiceis marked asexternally managed.static ScheduledExecutorServicestatic ScheduledExecutorServicestatic ExecutorServicesingleThreaded(String name) static ThreadFactorythreadNamingFactory(String threadBaseName) Create a thread factory based onExecutors.defaultThreadFactory(), but naming the created threads using the giventhreadBaseNameand an incrementing number for each thread created by the factory.static ThreadFactorythreadNamingFactory(LongFunction<String> threadName) Create a thread factory based onExecutors.defaultThreadFactory(), but naming the created threads using the result of the given givenlong -> Stringfunction, which argument is the number of the created thread.static ThreadFactorythreadNamingFactory(LongFunction<String> threadName, ThreadFactory backingFactory) Create a thread factory delegating to the givenbackingFactoryfor creating new threads, but naming the created threads using the result of the given givenlong -> Stringfunction, which argument is the number of the created thread.
-
Method Details
-
fixedThreadPool
-
singleThreaded
-
scheduledSingleThreaded
-
scheduled
-
threadNamingFactory
Create a thread factory based onExecutors.defaultThreadFactory(), but naming the created threads using the giventhreadBaseNameand an incrementing number for each thread created by the factory. The threads will have names on the formthreadBaseName-N.- Parameters:
threadBaseName- the base name for threads created by the factory.
-
threadNamingFactory
Create a thread factory based onExecutors.defaultThreadFactory(), but naming the created threads using the result of the given givenlong -> Stringfunction, which argument is the number of the created thread.- Parameters:
threadName- function used for naming each thread created by the factory.
-
threadNamingFactory
public static ThreadFactory threadNamingFactory(LongFunction<String> threadName, ThreadFactory backingFactory) Create a thread factory delegating to the givenbackingFactoryfor creating new threads, but naming the created threads using the result of the given givenlong -> Stringfunction, which argument is the number of the created thread.- Parameters:
threadName- function used for naming each thread created by the factory.backingFactory- the factory used for creating new threads.
-
externallyManaged
Wraps anotherExecutorServiceas 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 ofExecutorService.isTerminated())
ensureShutdown(ExecutorService, Duration). -
isExternallyManaged
Determine if the givenExecutorServiceis marked asexternally managed. -
ensureShutdown
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. TheensureShutdown(String, ExecutorService, Duration)method is preferred over this.- Parameters:
executor- theExecutorServiceto shut down.timeoutBeforeForcefulShutdown- the maximum amount of time to wait for tasks to finish before forcefully shutting down the executor.
-
ensureShutdown
public 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.- Parameters:
executorName- a descriptive name of the executor to shut down, used for logging.executor- theExecutorServiceto shut down.timeoutBeforeForcefulShutdown- the maximum amount of time to wait for tasks to finish before forcefully shutting down the executor.
-