Class ThreadPoolManager
java.lang.Object
org.apache.commons.jcs3.utils.threadpool.ThreadPoolManager
This manages threadpools for an application
It is a singleton since threads need to be managed vm wide.
This manager forces you to use a bounded queue. By default it uses the current thread for execution when the buffer is full and no free threads can be created.
You can specify the props file to use or pass in a properties object prior to configuration.
If set, the Properties object will take precedence.
If a value is not set for a particular pool, the hard coded defaults in PoolConfiguration
will be used.
You can configure default settings by specifying thread_pool.default
in the properties, ie "cache.ccf"
-
Method Summary
Modifier and TypeMethodDescriptioncreatePool
(PoolConfiguration config, String threadNamePrefix) Creates a pool based on the configuration info.createPool
(PoolConfiguration config, String threadNamePrefix, int threadPriority) Creates a pool based on the configuration info.createSchedulerPool
(PoolConfiguration config, String threadNamePrefix, int threadPriority) Creates a scheduler pool based on the configuration info.static void
dispose()
Dispose of the instance of the ThreadPoolManger and shut down all thread poolsgetExecutorService
(String name) Returns an executor service by name.static ThreadPoolManager
Returns a configured instance of the ThreadPoolManger To specify a configuration file or Properties object to use call the appropriate setter prior to calling getInstance.Returns the names of all configured pools.getSchedulerPool
(String name) Returns a scheduler pool by name.static void
setProps
(Properties props) This will be used if it is not null on initialization.
-
Method Details
-
createPool
Creates a pool based on the configuration info.- Parameters:
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the pool- Returns:
- A ThreadPool wrapper
-
createPool
public ExecutorService createPool(PoolConfiguration config, String threadNamePrefix, int threadPriority) Creates a pool based on the configuration info.- Parameters:
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the poolthreadPriority
- the priority of the created threads- Returns:
- A ThreadPool wrapper
-
createSchedulerPool
public ScheduledExecutorService createSchedulerPool(PoolConfiguration config, String threadNamePrefix, int threadPriority) Creates a scheduler pool based on the configuration info.- Parameters:
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the poolthreadPriority
- the priority of the created threads- Returns:
- A ScheduledExecutorService
-
getInstance
Returns a configured instance of the ThreadPoolManger To specify a configuration file or Properties object to use call the appropriate setter prior to calling getInstance.- Returns:
- The single instance of the ThreadPoolManager
-
dispose
Dispose of the instance of the ThreadPoolManger and shut down all thread pools -
getExecutorService
Returns an executor service by name. If a service by this name does not exist in the configuration file or properties, one will be created using the default values.Services are lazily created.
- Parameters:
name
-- Returns:
- The executor service configured for the name.
-
getSchedulerPool
Returns a scheduler pool by name. If a pool by this name does not exist in the configuration file or properties, one will be created using the default values.Pools are lazily created.
- Parameters:
name
-- Returns:
- The scheduler pool configured for the name.
-
getPoolNames
Returns the names of all configured pools.- Returns:
- ArrayList of string names
-
setProps
This will be used if it is not null on initialization. Setting this post initialization will have no effect.- Parameters:
props
- The props to set.
-