Package org.forgerock.util.thread
Class ExecutorServiceFactory
java.lang.Object
org.forgerock.util.thread.ExecutorServiceFactory
Responsible for generating ExecutorService instances which are automatically
wired up to shutdown when the ShutdownListener event triggers.
This factory simplifies the creation of ExecutorServices which could overlook
the important step of registering with the ShutdownManager. Failure to do so
will prevent the server from shutting down.
Note: Executors created using this factory will be triggered with the
ExecutorService#shutdownNow method. This will interrupt all blocking calls
made by those threads. This may be important for some users.
- Since:
- 1.3.5
-
Constructor Summary
ConstructorDescriptionExecutorServiceFactory
(ShutdownManager shutdownManager) Create an instance of the factory. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.createCachedThreadPool
(String threadNamePrefix) Generates a Cached Thread Pool ExecutorService using the provided name as a prefix of the thread names.createCachedThreadPool
(ThreadFactory factory) Generates a Cached Thread Pool ExecutorService which has been pre-registered with the ShutdownManager.createCancellableScheduledService
(int poolSize, String threadNamePrefix) Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager and has the remove on cancel policy enabled.createFixedThreadPool
(int pool) Deprecated.createFixedThreadPool(int, String)
should be used so that threads have meaningful names.createFixedThreadPool
(int pool, String threadNamePrefix) Create a fixed size Thread Pool ExecutorService using the provided name as the prefix of the thread names.createFixedThreadPool
(int pool, ThreadFactory factory) Creates a fixed size Thread Pool ExecutorService which has been pre-registered with theShutdownManager
.createScheduledService
(int poolSize) Deprecated.createScheduledService(int, String)
should be used so that threads have meaningful names.createScheduledService
(int poolSize, String threadNamePrefix) Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.createThreadPool
(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables) Deprecated.createThreadPool(int, int, long, TimeUnit, BlockingQueue, String)
should be used so that threads have meaningful names.createThreadPool
(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables, String threadNamePrefix) Generates a ThreadPoolExecutor with the provided values, and registers that executor as listening for shutdown messages.
-
Constructor Details
-
ExecutorServiceFactory
Create an instance of the factory.- Parameters:
shutdownManager
- Required to ensure each ExecutorService will be shutdown.
-
-
Method Details
-
createScheduledService
Deprecated.createScheduledService(int, String)
should be used so that threads have meaningful names.Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.- Parameters:
poolSize
- The size of the ScheduledExecutorService thread pool.- Returns:
- A non null ScheduledExecutorService
- See Also:
-
createScheduledService
Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.- Parameters:
poolSize
- The size of the ScheduledExecutorService thread pool.threadNamePrefix
- The thread name prefix to use when generating new threads.- Returns:
- A non null ScheduledExecutorService
- See Also:
-
createCancellableScheduledService
public ScheduledExecutorService createCancellableScheduledService(int poolSize, String threadNamePrefix) Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager and has the remove on cancel policy enabled.- Parameters:
poolSize
- The size of the ScheduledExecutorService thread pool.threadNamePrefix
- The thread name prefix to use when generating new threads.- Returns:
- A non null ScheduledExecutorService
- See Also:
-
createFixedThreadPool
Creates a fixed size Thread Pool ExecutorService which has been pre-registered with theShutdownManager
.- Parameters:
pool
- The size of the pool to create.factory
- TheThreadFactory
used to generate new threads.- Returns:
- Non null.
-
createFixedThreadPool
Create a fixed size Thread Pool ExecutorService using the provided name as the prefix of the thread names.- Parameters:
pool
- Size of the fixed pool.threadNamePrefix
- The thread name prefix to use when generating new threads.- Returns:
- Non null.
- See Also:
-
createFixedThreadPool
Deprecated.createFixedThreadPool(int, String)
should be used so that threads have meaningful names.Create a fixed size Thread Pool ExecutorService.- Parameters:
pool
- Size of the fixed pool.- Returns:
- Non null.
- See Also:
-
createCachedThreadPool
Generates a Cached Thread Pool ExecutorService which has been pre-registered with the ShutdownManager. The provided ThreadFactory is used by the service when creating Threads.- Parameters:
factory
- The ThreadFactory that will be used when generating threads. May not be null.- Returns:
- A non null ExecutorService.
- See Also:
-
createCachedThreadPool
Generates a Cached Thread Pool ExecutorService using the provided name as a prefix of the thread names.- Parameters:
threadNamePrefix
- The thread name prefix to use when generating new threads.- Returns:
- Non null.
- See Also:
-
createCachedThreadPool
Deprecated.createCachedThreadPool(String)
orcreateCachedThreadPool(ThreadFactory)
should be used so that threads have meaningful names.Generates a Cached Thread Pool ExecutorService.- Returns:
- Non null.
- See Also:
-
createThreadPool
@Deprecated public ExecutorService createThreadPool(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables) Deprecated.createThreadPool(int, int, long, TimeUnit, BlockingQueue, String)
should be used so that threads have meaningful names.Generates a ThreadPoolExecutor with the provided values, and registers that executor as listening for shutdown messages.- Parameters:
coreSize
- the number of threads to keep in the pool, even if they are idlemaxSize
- Max number of threads in the poolidleTimeout
- When the number of threads is greater than core, maximum time that excess idle threads will wait before terminatingtimeoutTimeunit
- The time unit for the idleTimeout argumentrunnables
- Queue of threads to be run- Returns:
- a configured ExecutorService, registered to listen to shutdown messages.
-
createThreadPool
public ExecutorService createThreadPool(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables, String threadNamePrefix) Generates a ThreadPoolExecutor with the provided values, and registers that executor as listening for shutdown messages.- Parameters:
coreSize
- the number of threads to keep in the pool, even if they are idlemaxSize
- Max number of threads in the poolidleTimeout
- When the number of threads is greater than core, maximum time that excess idle threads will wait before terminatingtimeoutTimeunit
- The time unit for the idleTimeout argumentrunnables
- Queue of threads to be runthreadNamePrefix
- The thread name prefix to use when generating new threads.- Returns:
- a configured ExecutorService, registered to listen to shutdown messages.
-
createCachedThreadPool(String)
orcreateCachedThreadPool(ThreadFactory)
should be used so that threads have meaningful names.