Class ThreadPoolConfig
- java.lang.Object
-
- org.glassfish.jersey.jdk.connector.internal.ThreadPoolConfig
-
public final class ThreadPoolConfig extends java.lang.Object
Client thread pool configuration, which might be used to customize client thread pool. One can get a default ThreadPoolConfig usingdefaultConfig()
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);
-
-
Field Summary
Fields Modifier and Type Field 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
-
Constructor Summary
Constructors Modifier Constructor 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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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()
ReturnThreadFactory
that will be used to create thread pool threads.int
hashCode()
boolean
isDaemon()
Returntrue
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)
Settrue
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)
SetThreadFactory
that will be used to create thread pool threads.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_CORE_POOL_SIZE
private static final int DEFAULT_CORE_POOL_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_MAX_POOL_SIZE
private static final int DEFAULT_MAX_POOL_SIZE
-
DEFAULT_MAX_QUEUE_SIZE
private static final int DEFAULT_MAX_QUEUE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUT
private static final int DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT
private static final ThreadPoolConfig DEFAULT
-
poolName
private java.lang.String poolName
-
corePoolSize
private int corePoolSize
-
maxPoolSize
private int maxPoolSize
-
queue
private java.util.Queue<java.lang.Runnable> queue
-
queueLimit
private int queueLimit
-
keepAliveTimeMillis
private long keepAliveTimeMillis
-
threadFactory
private java.util.concurrent.ThreadFactory threadFactory
-
priority
private int priority
-
isDaemon
private boolean isDaemon
-
initialClassLoader
private java.lang.ClassLoader initialClassLoader
-
-
Constructor Detail
-
ThreadPoolConfig
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)
-
ThreadPoolConfig
private ThreadPoolConfig(ThreadPoolConfig cfg)
-
-
Method Detail
-
defaultConfig
public static ThreadPoolConfig defaultConfig()
Create new client thread pool configuration instance. The returned ThreadPoolConfig instance will be pre-configured with a default values.- Returns:
- client thread pool configuration instance.
-
copy
public ThreadPoolConfig copy()
Return a copy of this thread pool config.- Returns:
- a copy of this thread pool config.
-
getQueue
public 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.- Returns:
- queue that will be used to temporarily store tasks when all threads in the thread pool are busy.
-
setQueue
public 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.- Parameters:
queue
- queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.- Returns:
- the
ThreadPoolConfig
with the newQueue
implementation.
-
getThreadFactory
public java.util.concurrent.ThreadFactory getThreadFactory()
ReturnThreadFactory
that will be used to create thread pool threads. IfThreadFactory
is set, thenpriority
,isDaemon
,poolName
settings will not be considered when creating new threads.- Returns:
ThreadFactory
that will be used to create thread pool threads.
-
setThreadFactory
public ThreadPoolConfig setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
SetThreadFactory
that will be used to create thread pool threads.- Parameters:
threadFactory
- customThreadFactory
IfThreadFactory
is set, thenpriority
,isDaemon
,poolName
settings will not be considered when creating new threads.- Returns:
- the
ThreadPoolConfig
with the newThreadFactory
-
getPoolName
public java.lang.String getPoolName()
Return thread pool name. The default is "Tyrus-client".- Returns:
- the thread pool name.
-
setPoolName
public ThreadPoolConfig setPoolName(java.lang.String poolName)
Set thread pool name. The default is "Tyrus-client".- Parameters:
poolName
- the thread pool name.- Returns:
- the
ThreadPoolConfig
with 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
public ThreadPoolConfig setPriority(int priority)
Set priority of the threads in thread pool. The default isThread.NORM_PRIORITY
.- Parameters:
priority
- of the threads in thread pool.- Returns:
- the
ThreadPoolConfig
with the new thread priority.
-
isDaemon
public boolean isDaemon()
Returntrue
if thread pool threads are daemons. The default istrue
.- Returns:
true
if thread pool threads are daemons.
-
setDaemon
public ThreadPoolConfig setDaemon(boolean isDaemon)
Settrue
if thread pool threads are daemons. The default istrue
.- Parameters:
isDaemon
-true
if thread pool threads are daemons.- Returns:
- the
ThreadPoolConfig
with 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
public ThreadPoolConfig setMaxPoolSize(int maxPoolSize)
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
ThreadPoolConfig
with 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
public ThreadPoolConfig setCorePoolSize(int corePoolSize)
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
ThreadPoolConfig
with 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
public ThreadPoolConfig setQueueLimit(int queueLimit)
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. The queueLimit value less than 0 means unlimited queue.- Returns:
- the
ThreadPoolConfig
with the new queue limit.
-
setKeepAliveTime
public ThreadPoolConfig setKeepAliveTime(long time, java.util.concurrent.TimeUnit unit)
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 (seesetCorePoolSize(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
ThreadPoolConfig
with the new keep alive time.
-
getKeepAliveTime
public long getKeepAliveTime(java.util.concurrent.TimeUnit timeUnit)
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 (seesetCorePoolSize(int)
,setMaxPoolSize(int)
) - then the thread will be terminated and removed from the thread pool. The default is 10s.- Returns:
- the keep-alive timeout, the value less than 0 means no timeout.
-
getInitialClassLoader
public java.lang.ClassLoader 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.- Returns:
- the class loader (if any) to be initially exposed by threads from this pool.
-
setInitialClassLoader
public ThreadPoolConfig setInitialClassLoader(java.lang.ClassLoader initialClassLoader)
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
ThreadPoolConfig
with the class loader set. - See Also:
Thread.getContextClassLoader()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-