public final class ThreadPoolConfig
extends java.lang.Object
defaultConfig()
and customize it according to the application specific requirements.
A ThreadPoolConfig object might be customized in a "Builder"-like fashion:
ThreadPoolConfig.defaultConfig() .setPoolName("App1Pool") .setCorePoolSize(5) .setMaxPoolSize(10);
Modifier and Type | Field and Description |
---|---|
private int |
corePoolSize |
private static ThreadPoolConfig |
DEFAULT |
private static int |
DEFAULT_CORE_POOL_SIZE |
private static int |
DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUT |
private static int |
DEFAULT_MAX_POOL_SIZE |
private static int |
DEFAULT_MAX_QUEUE_SIZE |
private java.lang.ClassLoader |
initialClassLoader |
private boolean |
isDaemon |
private long |
keepAliveTimeMillis |
private int |
maxPoolSize |
private java.lang.String |
poolName |
private int |
priority |
private java.util.Queue<java.lang.Runnable> |
queue |
private int |
queueLimit |
private java.util.concurrent.ThreadFactory |
threadFactory |
Modifier | Constructor and Description |
---|---|
private |
ThreadPoolConfig(java.lang.String poolName,
int corePoolSize,
int maxPoolSize,
java.util.Queue<java.lang.Runnable> queue,
int queueLimit,
long keepAliveTime,
java.util.concurrent.TimeUnit timeUnit,
java.util.concurrent.ThreadFactory threadFactory,
int priority,
boolean isDaemon,
java.lang.ClassLoader initialClassLoader) |
private |
ThreadPoolConfig(ThreadPoolConfig cfg) |
Modifier and Type | Method and Description |
---|---|
ThreadPoolConfig |
copy()
Return a copy of this thread pool config.
|
static ThreadPoolConfig |
defaultConfig()
Create new client thread pool configuration instance.
|
boolean |
equals(java.lang.Object o) |
int |
getCorePoolSize()
Get the core thread pool size - the size of the thread pool will never bee smaller than this.
|
java.lang.ClassLoader |
getInitialClassLoader()
Get the class loader (if any) to be initially exposed by threads from this pool.
|
long |
getKeepAliveTime(java.util.concurrent.TimeUnit timeUnit)
Get the max period of time a thread will wait for a new task to process.
|
int |
getMaxPoolSize()
Get max thread pool size.
|
java.lang.String |
getPoolName()
Return thread pool name.
|
int |
getPriority()
Get priority of the threads in thread pool.
|
java.util.Queue<java.lang.Runnable> |
getQueue()
Return a queue that will be used to temporarily store tasks when all threads in the thread pool are busy.
|
int |
getQueueLimit()
Get the limit of the queue, where tasks are temporarily stored when all threads are busy.
|
java.util.concurrent.ThreadFactory |
getThreadFactory()
Return
ThreadFactory that will be used to create thread pool threads. |
int |
hashCode() |
boolean |
isDaemon()
Return
true if thread pool threads are daemons. |
ThreadPoolConfig |
setCorePoolSize(int corePoolSize)
Set the core thread pool size - the size of the thread pool will never bee smaller than this.
|
ThreadPoolConfig |
setDaemon(boolean isDaemon)
Set
true if thread pool threads are daemons. |
ThreadPoolConfig |
setInitialClassLoader(java.lang.ClassLoader initialClassLoader)
Specifies the context class loader that will be used by threads in this pool.
|
ThreadPoolConfig |
setKeepAliveTime(long time,
java.util.concurrent.TimeUnit unit)
The max period of time a thread will wait for a new task to process.
|
ThreadPoolConfig |
setMaxPoolSize(int maxPoolSize)
Set max thread pool size.
|
ThreadPoolConfig |
setPoolName(java.lang.String poolName)
Set thread pool name.
|
ThreadPoolConfig |
setPriority(int priority)
Set priority of the threads in thread pool.
|
ThreadPoolConfig |
setQueue(java.util.Queue<java.lang.Runnable> queue)
Set a queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.
|
ThreadPoolConfig |
setQueueLimit(int queueLimit)
Set the limit of the queue, where tasks are temporarily stored when all threads are busy.
|
ThreadPoolConfig |
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Set
ThreadFactory that will be used to create thread pool threads. |
java.lang.String |
toString() |
private static final int DEFAULT_CORE_POOL_SIZE
private static final int DEFAULT_MAX_POOL_SIZE
private static final int DEFAULT_MAX_QUEUE_SIZE
private static final int DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUT
private static final ThreadPoolConfig DEFAULT
private java.lang.String poolName
private int corePoolSize
private int maxPoolSize
private java.util.Queue<java.lang.Runnable> queue
private int queueLimit
private long keepAliveTimeMillis
private java.util.concurrent.ThreadFactory threadFactory
private int priority
private boolean isDaemon
private java.lang.ClassLoader initialClassLoader
private ThreadPoolConfig(java.lang.String poolName, int corePoolSize, int maxPoolSize, java.util.Queue<java.lang.Runnable> queue, int queueLimit, long keepAliveTime, java.util.concurrent.TimeUnit timeUnit, java.util.concurrent.ThreadFactory threadFactory, int priority, boolean isDaemon, java.lang.ClassLoader initialClassLoader)
private ThreadPoolConfig(ThreadPoolConfig cfg)
public static ThreadPoolConfig defaultConfig()
public ThreadPoolConfig copy()
public java.util.Queue<java.lang.Runnable> getQueue()
public ThreadPoolConfig setQueue(java.util.Queue<java.lang.Runnable> queue)
queue
- queue implementation that will be used to temporarily store tasks when all threads in the thread pool are
busy.ThreadPoolConfig
with the new Queue
implementation.public java.util.concurrent.ThreadFactory getThreadFactory()
ThreadFactory
that will be used to create thread pool threads.
If ThreadFactory
is set, then priority
, isDaemon
,
poolName
settings will not be considered when creating new threads.ThreadFactory
that will be used to create thread pool threads.public ThreadPoolConfig setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
ThreadFactory
that will be used to create thread pool threads.threadFactory
- custom ThreadFactory
If ThreadFactory
is set, then priority
, isDaemon
,
poolName
settings will not be considered when creating new threads.ThreadPoolConfig
with the new ThreadFactory
public java.lang.String getPoolName()
public ThreadPoolConfig setPoolName(java.lang.String poolName)
poolName
- the thread pool name.ThreadPoolConfig
with the new thread pool name.public int getPriority()
Thread.NORM_PRIORITY
.public ThreadPoolConfig setPriority(int priority)
Thread.NORM_PRIORITY
.priority
- of the threads in thread pool.ThreadPoolConfig
with the new thread priority.public boolean isDaemon()
true
if thread pool threads are daemons. The default is true
.true
if thread pool threads are daemons.public ThreadPoolConfig setDaemon(boolean isDaemon)
true
if thread pool threads are daemons. The default is true
.isDaemon
- true
if thread pool threads are daemons.ThreadPoolConfig
with the daemon property set.public int getMaxPoolSize()
Math.max(Runtime.getRuntime().availableProcessors(), 20)
public ThreadPoolConfig setMaxPoolSize(int maxPoolSize)
Math.max(Runtime.getRuntime().availableProcessors(), 20)
.
Cannot be smaller than 3.maxPoolSize
- the max thread pool size.ThreadPoolConfig
with the new max pool size set.public int getCorePoolSize()
public ThreadPoolConfig setCorePoolSize(int corePoolSize)
corePoolSize
- the core thread pool size - the size of the thread pool will never bee smaller than this.ThreadPoolConfig
with the new core pool size set.public int getQueueLimit()
public ThreadPoolConfig setQueueLimit(int queueLimit)
queueLimit
- the thread pool queue limit. The queueLimit value less than 0 means unlimited queue.ThreadPoolConfig
with the new queue limit.public ThreadPoolConfig setKeepAliveTime(long time, java.util.concurrent.TimeUnit unit)
setCorePoolSize(int)
, setMaxPoolSize(int)
)
- then the thread will be terminated and removed from the thread pool.
The default is 10s.time
- max keep alive timeout. The value less than 0 means no timeout.unit
- time unit.ThreadPoolConfig
with the new keep alive time.public long getKeepAliveTime(java.util.concurrent.TimeUnit timeUnit)
setCorePoolSize(int)
, setMaxPoolSize(int)
)
- then the thread will be terminated and removed from the thread pool.
The default is 10s.public java.lang.ClassLoader getInitialClassLoader()
public ThreadPoolConfig setInitialClassLoader(java.lang.ClassLoader initialClassLoader)
initialClassLoader
- the class loader to be exposed by threads of this pool.ThreadPoolConfig
with the class loader set.Thread.getContextClassLoader()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object