public class ThreadPoolManager extends Object
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"
Modifier and Type | Method and Description |
---|---|
ExecutorService |
createPool(PoolConfiguration config,
String threadNamePrefix)
Creates a pool based on the configuration info.
|
ExecutorService |
createPool(PoolConfiguration config,
String threadNamePrefix,
int threadPriority)
Creates a pool based on the configuration info.
|
ScheduledExecutorService |
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 pools
|
ExecutorService |
getExecutorService(String name)
Returns an executor service by name.
|
static ThreadPoolManager |
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.
|
protected Set<String> |
getPoolNames()
Returns the names of all configured pools.
|
ScheduledExecutorService |
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.
|
public ExecutorService createPool(PoolConfiguration config, String threadNamePrefix)
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the poolpublic ExecutorService createPool(PoolConfiguration config, String threadNamePrefix, int threadPriority)
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the poolthreadPriority
- the priority of the created threadspublic ScheduledExecutorService createSchedulerPool(PoolConfiguration config, String threadNamePrefix, int threadPriority)
config
- the pool configurationthreadNamePrefix
- prefix for the thread names of the poolthreadPriority
- the priority of the created threadspublic static ThreadPoolManager getInstance()
public static void dispose()
public ExecutorService getExecutorService(String name)
Services are lazily created.
name
- public ScheduledExecutorService getSchedulerPool(String name)
Pools are lazily created.
name
- protected Set<String> getPoolNames()
public static void setProps(Properties props)
props
- The props to set.Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.