Package org.forgerock.util.thread
Class ExecutorServiceFactory
- java.lang.Object
-
- org.forgerock.util.thread.ExecutorServiceFactory
-
public class ExecutorServiceFactory extends Object
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
Constructors Constructor Description ExecutorServiceFactory(ShutdownManager shutdownManager)
Create an instance of the factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ExecutorService
createCachedThreadPool()
Deprecated.createCachedThreadPool(String)
orcreateCachedThreadPool(ThreadFactory)
should be used so that threads have meaningful names.ExecutorService
createCachedThreadPool(String threadNamePrefix)
Generates a Cached Thread Pool ExecutorService using the provided name as a prefix of the thread names.ExecutorService
createCachedThreadPool(ThreadFactory factory)
Generates a Cached Thread Pool ExecutorService which has been pre-registered with the ShutdownManager.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.ExecutorService
createFixedThreadPool(int pool)
Deprecated.createFixedThreadPool(int, String)
should be used so that threads have meaningful names.ExecutorService
createFixedThreadPool(int pool, String threadNamePrefix)
Create a fixed size Thread Pool ExecutorService using the provided name as the prefix of the thread names.ExecutorService
createFixedThreadPool(int pool, ThreadFactory factory)
Creates a fixed size Thread Pool ExecutorService which has been pre-registered with theShutdownManager
.ScheduledExecutorService
createScheduledService(int poolSize)
Deprecated.createScheduledService(int, String)
should be used so that threads have meaningful names.ScheduledExecutorService
createScheduledService(int poolSize, String threadNamePrefix)
Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.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.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.
-
-
-
Constructor Detail
-
ExecutorServiceFactory
public ExecutorServiceFactory(ShutdownManager shutdownManager)
Create an instance of the factory.- Parameters:
shutdownManager
- Required to ensure each ExecutorService will be shutdown.
-
-
Method Detail
-
createScheduledService
@Deprecated public ScheduledExecutorService createScheduledService(int poolSize)
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:
Executors.newScheduledThreadPool(int)
-
createScheduledService
public ScheduledExecutorService createScheduledService(int poolSize, String threadNamePrefix)
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:
Executors.newScheduledThreadPool(int)
-
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:
Executors.newScheduledThreadPool(int)
-
createFixedThreadPool
public ExecutorService createFixedThreadPool(int pool, ThreadFactory factory)
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
public ExecutorService createFixedThreadPool(int pool, String threadNamePrefix)
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(int, java.util.concurrent.ThreadFactory)
-
createFixedThreadPool
@Deprecated public ExecutorService createFixedThreadPool(int pool)
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:
createFixedThreadPool(int, java.util.concurrent.ThreadFactory)
-
createCachedThreadPool
public ExecutorService createCachedThreadPool(ThreadFactory factory)
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:
Executors.newCachedThreadPool(java.util.concurrent.ThreadFactory)
-
createCachedThreadPool
public ExecutorService createCachedThreadPool(String threadNamePrefix)
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(java.util.concurrent.ThreadFactory)
-
createCachedThreadPool
@Deprecated public ExecutorService 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:
createCachedThreadPool(java.util.concurrent.ThreadFactory)
-
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.
-
-