Class ThreadPoolConfig
One can get a default ThreadPoolConfig using 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);
- Author:
- Oleksiy Stashok, gustav trede
-
Method Summary
Modifier and TypeMethodDescriptioncopy()Return a copy of this thread pool config.static ThreadPoolConfigCreate new client thread pool configuration instance.booleanintGet the core thread pool size - the size of the thread pool will never bee smaller than this.Get the class loader (if any) to be initially exposed by threads from this pool.longgetKeepAliveTime(TimeUnit timeUnit) Get the max period of time a thread will wait for a new task to process.intGet max thread pool size.Return thread pool name.intGet priority of the threads in thread pool.getQueue()Return a queue that will be used to temporarily store tasks when all threads in the thread pool are busy.intGet the limit of the queue, where tasks are temporarily stored when all threads are busy.ReturnThreadFactorythat will be used to create thread pool threads.inthashCode()booleanisDaemon()Returntrueif thread pool threads are daemons.setCorePoolSize(int corePoolSize) Set the core thread pool size - the size of the thread pool will never bee smaller than this.setDaemon(boolean isDaemon) Settrueif thread pool threads are daemons.setInitialClassLoader(ClassLoader initialClassLoader) Specifies the context class loader that will be used by threads in this pool.setKeepAliveTime(long time, TimeUnit unit) The max period of time a thread will wait for a new task to process.setMaxPoolSize(int maxPoolSize) Set max thread pool size.setPoolName(String poolName) Set thread pool name.setPriority(int priority) Set priority of the threads in thread pool.Set a queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.setQueueLimit(int queueLimit) Set the limit of the queue, where tasks are temporarily stored when all threads are busy.setThreadFactory(ThreadFactory threadFactory) SetThreadFactorythat will be used to create thread pool threads.toString()
-
Method Details
-
defaultConfig
Create new client thread pool configuration instance. The returnedThreadPoolConfiginstance will be pre-configured with a default values.- Returns:
- client thread pool configuration instance.
-
copy
Return a copy of this thread pool config.- Returns:
- a copy of this thread pool config.
-
getQueue
Return a queue that will be used to temporarily store tasks when all threads in the thread pool are busy.- Returns:
- queue that will be used to temporarily store tasks when all threads in the thread pool are busy.
-
setQueue
Set a queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.- Parameters:
queue- queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.- Returns:
- the
ThreadPoolConfigwith the newQueueimplementation.
-
getThreadFactory
ReturnThreadFactorythat will be used to create thread pool threads.If
ThreadFactoryis set, thenpriority,isDaemon,poolNamesettings will not be considered when creating new threads.- Returns:
ThreadFactorythat will be used to create thread pool threads.
-
setThreadFactory
SetThreadFactorythat will be used to create thread pool threads.- Parameters:
threadFactory- customThreadFactoryIfThreadFactoryis set, thenpriority,isDaemon,poolNamesettings will not be considered when creating new threads.- Returns:
- the
ThreadPoolConfigwith the newThreadFactory
-
getPoolName
Return thread pool name. The default is "Tyrus-client".- Returns:
- the thread pool name.
-
setPoolName
Set thread pool name. The default is "Tyrus-client".- Parameters:
poolName- the thread pool name.- Returns:
- the
ThreadPoolConfigwith the new thread pool name.
-
getPriority
public int getPriority()Get priority of the threads in thread pool. The default isThread.NORM_PRIORITY.- Returns:
- priority of the threads in thread pool.
-
setPriority
Set priority of the threads in thread pool. The default isThread.NORM_PRIORITY.- Parameters:
priority- of the threads in thread pool.- Returns:
- the
ThreadPoolConfigwith the new thread priority.
-
isDaemon
public boolean isDaemon()Returntrueif thread pool threads are daemons. The default istrue.- Returns:
trueif thread pool threads are daemons.
-
setDaemon
Settrueif thread pool threads are daemons. The default istrue.- Parameters:
isDaemon-trueif thread pool threads are daemons.- Returns:
- the
ThreadPoolConfigwith the daemon property set.
-
getMaxPoolSize
public int getMaxPoolSize()Get max thread pool size. The default isMath.max(Runtime.getRuntime().availableProcessors(), 20)- Returns:
- max thread pool size.
-
setMaxPoolSize
Set max thread pool size. The default is The default isMath.max(Runtime.getRuntime().availableProcessors(), 20).Cannot be smaller than 3.
- Parameters:
maxPoolSize- the max thread pool size.- Returns:
- the
ThreadPoolConfigwith the new max pool size set.
-
getCorePoolSize
public int getCorePoolSize()Get the core thread pool size - the size of the thread pool will never bee smaller than this.The default is 1.
- Returns:
- the core thread pool size - the size of the thread pool will never bee smaller than this.
-
setCorePoolSize
Set the core thread pool size - the size of the thread pool will never bee smaller than this.The default is 1.
- Parameters:
corePoolSize- the core thread pool size - the size of the thread pool will never bee smaller than this.- Returns:
- the
ThreadPoolConfigwith the new core pool size set.
-
getQueueLimit
public int getQueueLimit()Get the limit of the queue, where tasks are temporarily stored when all threads are busy.Value less than 0 means unlimited queue. The default is -1.
- Returns:
- the thread-pool queue limit. The queue limit
-
setQueueLimit
Set the limit of the queue, where tasks are temporarily stored when all threads are busy.Value less than 0 means unlimited queue. The default is -1.
- Parameters:
queueLimit- the thread pool queue limit. ThequeueLimitvalue less than 0 means unlimited queue.- Returns:
- the
ThreadPoolConfigwith the new queue limit.
-
setKeepAliveTime
The max period of time a thread will wait for a new task to process.If the timeout expires and the thread is not a core one (see
setCorePoolSize(int),setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.The default is 10s.
- Parameters:
time- max keep alive timeout. The value less than 0 means no timeout.unit- time unit.- Returns:
- the
ThreadPoolConfigwith the new keep alive time.
-
getKeepAliveTime
Get the max period of time a thread will wait for a new task to process.If the timeout expires and the thread is not a core one (see
setCorePoolSize(int),setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.The default is 10s.
- Parameters:
timeUnit- time unit to which the result will be converted.- Returns:
- the keep-alive timeout, the value less than 0 means no timeout.
-
getInitialClassLoader
Get the class loader (if any) to be initially exposed by threads from this pool.If not specified, the class loader of the parent thread that initialized the pool will be used.Authen
- Returns:
- the class loader (if any) to be initially exposed by threads from this pool.
-
setInitialClassLoader
Specifies the context class loader that will be used by threads in this pool.If not specified, the class loader of the parent thread that initialized the pool will be used.
- Parameters:
initialClassLoader- the class loader to be exposed by threads of this pool.- Returns:
- the
ThreadPoolConfigwith the class loader set. - See Also:
-
toString
-
equals
-
hashCode
public int hashCode()
-