public final class ThreadPoolConfig extends 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 | 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(Object o) |
int |
getCorePoolSize()
Get the core thread pool size - the size of the thread pool will never bee smaller than this.
|
ClassLoader |
getInitialClassLoader()
Get the class loader (if any) to be initially exposed by threads from this pool.
|
long |
getKeepAliveTime(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.
|
String |
getPoolName()
Return thread pool name.
|
int |
getPriority()
Get priority of the threads in thread pool.
|
Queue<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.
|
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(ClassLoader initialClassLoader)
Specifies the context class loader that will be used by threads in this pool.
|
ThreadPoolConfig |
setKeepAliveTime(long time,
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(String poolName)
Set thread pool name.
|
ThreadPoolConfig |
setPriority(int priority)
Set priority of the threads in thread pool.
|
ThreadPoolConfig |
setQueue(Queue<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(ThreadFactory threadFactory)
Set
ThreadFactory that will be used to create thread pool threads. |
String |
toString() |
public static ThreadPoolConfig defaultConfig()
public ThreadPoolConfig copy()
public Queue<Runnable> getQueue()
public ThreadPoolConfig setQueue(Queue<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 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(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 String getPoolName()
public ThreadPoolConfig setPoolName(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, 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(TimeUnit timeUnit)
setCorePoolSize(int)
, setMaxPoolSize(int)
)
- then the thread will be terminated and removed from the thread pool.
The default is 10s.public ClassLoader getInitialClassLoader()
public ThreadPoolConfig setInitialClassLoader(ClassLoader initialClassLoader)
initialClassLoader
- the class loader to be exposed by threads of this pool.ThreadPoolConfig
with the class loader set.Thread.getContextClassLoader()
Copyright © 2007-2023, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.