Top Description Fields Constructors Methods
org.glassfish.tyrus.client

public final Class ThreadPoolConfig

extends Object
Class Inheritance
Imports
java.util.Queue, java.util.concurrent.ThreadFactory, .TimeUnit

Client thread pool configuration, which might be used to customize client thread pool.

One can get a default ThreadPoolConfig using ThreadPoolConfig#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);
Authors
Oleksiy Stashok, gustav trede

Field Summary

Modifier and TypeField and Description
private int
private static final ThreadPoolConfig
private static final int
private static final int
private static final int
private static final int
private ClassLoader
private boolean
private long
private int
private String
private int
private Queue<Runnable>
private int
private ThreadFactory

Constructor Summary

AccessConstructor and Description
private
ThreadPoolConfig(String poolName, int corePoolSize, int maxPoolSize, Queue<Runnable> queue, int queueLimit, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory, int priority, boolean isDaemon, ClassLoader initialClassLoader)

private

Method Summary

Modifier and TypeMethod and Description
public ThreadPoolConfig

Returns:

a copy of this thread pool config.
copy
()

Return a copy of this thread pool config.

public static ThreadPoolConfig

Returns:

client thread pool configuration instance.
defaultConfig
()

Create new client thread pool configuration instance.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int

Returns:

the core thread pool size - the size of the thread pool will never bee smaller than this.
getCorePoolSize
()

Get the core thread pool size - the size of the thread pool will never bee smaller than this.

public ClassLoader

Returns:

the class loader (if any) to be initially exposed by threads from this pool.
getInitialClassLoader
()

Get the class loader (if any) to be initially exposed by threads from this pool.

public long

Returns:

the keep-alive timeout, the value less than 0 means no timeout.
getKeepAliveTime
(TimeUnit
time unit to which the result will be converted.
timeUnit
)

Get the max period of time a thread will wait for a new task to process.

public int

Returns:

max thread pool size.
getMaxPoolSize
()

Get max thread pool size.

public String

Returns:

the thread pool name.
getPoolName
()

Return thread pool name.

public int

Returns:

priority of the threads in thread pool.
getPriority
()

Get priority of the threads in thread pool.

public Queue<Runnable>

Returns:

queue that will be used to temporarily store tasks when all threads in the thread pool are busy.
getQueue
()

Return a queue that will be used to temporarily store tasks when all threads in the thread pool are busy.

public int

Returns:

the thread-pool queue limit. The queue limit
getQueueLimit
()

Get the limit of the queue, where tasks are temporarily stored when all threads are busy.

public ThreadFactory

Returns:

java.util.concurrent.ThreadFactory that will be used to create thread pool threads.
getThreadFactory
()

Return java.util.concurrent.ThreadFactory that will be used to create thread pool threads.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if thread pool threads are daemons.
isDaemon
()

Return true if thread pool threads are daemons.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new core pool size set.
setCorePoolSize
(int
the core thread pool size - the size of the thread pool will never bee smaller than this.
corePoolSize
)

Set the core thread pool size - the size of the thread pool will never bee smaller than this.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the daemon property set.
setDaemon
(boolean
true if thread pool threads are daemons.
isDaemon
)

Set true if thread pool threads are daemons.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the class loader set.
setInitialClassLoader
(final ClassLoader
the class loader to be exposed by threads of this pool.
initialClassLoader
)

Specifies the context class loader that will be used by threads in this pool.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new keep alive time.
setKeepAliveTime
(long
max keep alive timeout. The value less than 0 means no timeout.
time
,
TimeUnit
time unit.
unit
)

The max period of time a thread will wait for a new task to process.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new max pool size set.
setMaxPoolSize
(int
the max thread pool size.
maxPoolSize
)

Set max thread pool size.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new thread pool name.
setPoolName
(String
the thread pool name.
poolName
)

Set thread pool name.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new thread priority.
setPriority
(int
of the threads in thread pool.
priority
)

Set priority of the threads in thread pool.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new java.util.Queue implementation.
setQueue
(Queue<Runnable>
queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.
queue
)

Set a queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.

public ThreadPoolConfig

Returns:

the ThreadPoolConfig with the new queue limit.
setQueueLimit
(int
the thread pool queue limit. The queueLimit value less than 0 means unlimited queue.
queueLimit
)

Set the limit of the queue, where tasks are temporarily stored when all threads are busy.

public ThreadPoolConfig
setThreadFactory(ThreadFactory
custom java.util.concurrent.ThreadFactory If java.util.concurrent.ThreadFactory is set, then priority, isDaemon, poolName settings will not be considered when creating new threads.
threadFactory
)

Set java.util.concurrent.ThreadFactory that will be used to create thread pool threads.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

corePoolSizeback to summary
private int corePoolSize
DEFAULTback to summary
private static final ThreadPoolConfig DEFAULT
DEFAULT_CORE_POOL_SIZEback to summary
private static final int DEFAULT_CORE_POOL_SIZE
DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUTback to summary
private static final int DEFAULT_IDLE_THREAD_KEEP_ALIVE_TIMEOUT
DEFAULT_MAX_POOL_SIZEback to summary
private static final int DEFAULT_MAX_POOL_SIZE
DEFAULT_MAX_QUEUE_SIZEback to summary
private static final int DEFAULT_MAX_QUEUE_SIZE
initialClassLoaderback to summary
private ClassLoader initialClassLoader
isDaemonback to summary
private boolean isDaemon
keepAliveTimeMillisback to summary
private long keepAliveTimeMillis
maxPoolSizeback to summary
private int maxPoolSize
poolNameback to summary
private String poolName
priorityback to summary
private int priority
queueback to summary
private Queue<Runnable> queue
queueLimitback to summary
private int queueLimit
threadFactoryback to summary
private ThreadFactory threadFactory

Constructor Detail

ThreadPoolConfigback to summary
private ThreadPoolConfig(String poolName, int corePoolSize, int maxPoolSize, Queue<Runnable> queue, int queueLimit, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory, int priority, boolean isDaemon, ClassLoader initialClassLoader)
ThreadPoolConfigback to summary
private ThreadPoolConfig(ThreadPoolConfig cfg)

Method Detail

copyback to summary
public ThreadPoolConfig copy()

Return a copy of this thread pool config.

Returns:ThreadPoolConfig

a copy of this thread pool config.

defaultConfigback to summary
public static ThreadPoolConfig defaultConfig()

Create new client thread pool configuration instance. The returned ThreadPoolConfig instance will be pre-configured with a default values.

Returns:ThreadPoolConfig

client thread pool configuration instance.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCorePoolSizeback to summary
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:int

the core thread pool size - the size of the thread pool will never bee smaller than this.

getInitialClassLoaderback to summary
public 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.Authen

Returns:ClassLoader

the class loader (if any) to be initially exposed by threads from this pool.

getKeepAliveTimeback to summary
public long getKeepAliveTime(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 (see setCorePoolSize(int), setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.

The default is 10s.

Parameters
timeUnit:TimeUnit

time unit to which the result will be converted.

Returns:long

the keep-alive timeout, the value less than 0 means no timeout.

getMaxPoolSizeback to summary
public int getMaxPoolSize()

Get max thread pool size. The default is Math.max(Runtime.getRuntime().availableProcessors(), 20)

Returns:int

max thread pool size.

getPoolNameback to summary
public String getPoolName()

Return thread pool name. The default is "Tyrus-client".

Returns:String

the thread pool name.

getPriorityback to summary
public int getPriority()

Get priority of the threads in thread pool. The default is Thread#NORM_PRIORITY.

Returns:int

priority of the threads in thread pool.

getQueueback to summary
public Queue<Runnable> getQueue()

Return a queue that will be used to temporarily store tasks when all threads in the thread pool are busy.

Returns:Queue<Runnable>

queue that will be used to temporarily store tasks when all threads in the thread pool are busy.

getQueueLimitback to summary
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:int

the thread-pool queue limit. The queue limit

getThreadFactoryback to summary
public ThreadFactory getThreadFactory()

Return java.util.concurrent.ThreadFactory that will be used to create thread pool threads.

If java.util.concurrent.ThreadFactory is set, then priority, isDaemon, poolName settings will not be considered when creating new threads.

Returns:ThreadFactory

java.util.concurrent.ThreadFactory that will be used to create thread pool threads.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isDaemonback to summary
public boolean isDaemon()

Return true if thread pool threads are daemons. The default is true.

Returns:boolean

true if thread pool threads are daemons.

setCorePoolSizeback to summary
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:int

the core thread pool size - the size of the thread pool will never bee smaller than this.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new core pool size set.

setDaemonback to summary
public ThreadPoolConfig setDaemon(boolean isDaemon)

Set true if thread pool threads are daemons. The default is true.

Parameters
isDaemon:boolean

true if thread pool threads are daemons.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the daemon property set.

setInitialClassLoaderback to summary
public ThreadPoolConfig setInitialClassLoader(final 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:ClassLoader

the class loader to be exposed by threads of this pool.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the class loader set.

See Also
Thread#getContextClassLoader()
setKeepAliveTimeback to summary
public ThreadPoolConfig setKeepAliveTime(long time, 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 (see setCorePoolSize(int), setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.

The default is 10s.

Parameters
time:long

max keep alive timeout. The value less than 0 means no timeout.

unit:TimeUnit

time unit.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new keep alive time.

setMaxPoolSizeback to summary
public ThreadPoolConfig setMaxPoolSize(int maxPoolSize)

Set max thread pool size. The default is The default is Math.max(Runtime.getRuntime().availableProcessors(), 20).

Cannot be smaller than 3.

Parameters
maxPoolSize:int

the max thread pool size.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new max pool size set.

setPoolNameback to summary
public ThreadPoolConfig setPoolName(String poolName)

Set thread pool name. The default is "Tyrus-client".

Parameters
poolName:String

the thread pool name.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new thread pool name.

setPriorityback to summary
public ThreadPoolConfig setPriority(int priority)

Set priority of the threads in thread pool. The default is Thread#NORM_PRIORITY.

Parameters
priority:int

of the threads in thread pool.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new thread priority.

setQueueback to summary
public 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.

Parameters
queue:Queue<Runnable>

queue implementation that will be used to temporarily store tasks when all threads in the thread pool are busy.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new java.util.Queue implementation.

setQueueLimitback to summary
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:int

the thread pool queue limit. The queueLimit value less than 0 means unlimited queue.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new queue limit.

setThreadFactoryback to summary
public ThreadPoolConfig setThreadFactory(ThreadFactory threadFactory)

Set java.util.concurrent.ThreadFactory that will be used to create thread pool threads.

Parameters
threadFactory:ThreadFactory

custom java.util.concurrent.ThreadFactory If java.util.concurrent.ThreadFactory is set, then priority, isDaemon, poolName settings will not be considered when creating new threads.

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new java.util.concurrent.ThreadFactory

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override