Top Description Fields Constructors Methods
org.glassfish.grizzly.threadpool

public final Class ThreadPoolConfig

extends Object
Class Inheritance
Imports
java.util.Queue, java.util.concurrent.ThreadFactory, .TimeUnit, org.glassfish.grizzly.memory.MemoryManager, org.glassfish.grizzly.monitoring.DefaultMonitoringConfig, org.glassfish.grizzly.utils.DelayedExecutor

Grizzly thread-pool configuration, which might be used to create and initialize a thread-pool via GrizzlyExecutorService#createInstance(org.glassfish.grizzly.threadpool.ThreadPoolConfig). One can get a default Grizzly ThreadPoolConfig using org.glassfish.grizzly.threadpool.ThreadPoolConfig#copy() 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
protected int
private static final ThreadPoolConfig
protected ClassLoader
protected boolean
protected long
protected int
protected MemoryManager<E extends Buffer>
protected String
protected int
protected Queue<Runnable>
protected int
protected ThreadFactory
protected final DefaultMonitoringConfig<ThreadPoolProbe>
threadPoolMonitoringConfig

Thread pool probes

protected DelayedExecutor
protected long

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, MemoryManager<E extends Buffer> mm, DelayedExecutor transactionMonitor, long transactionTimeoutMillis, ClassLoader initialClassLoader)

private

Method Summary

Modifier and TypeMethod and Description
public ThreadPoolConfig
copy()

public static ThreadPoolConfig

Returns:

the Grizzly thread-pool configuration instance.
defaultConfig
()

Create new Grizzly thread-pool configuration instance.

public int
getCorePoolSize()

Returns: the corepoolsize

public ClassLoader
getInitialClassLoader()

Returns: the classloader (if any) to be initially exposed by threads from this pool.

public DefaultMonitoringConfig<ThreadPoolProbe>
public long

Returns:

the keep-alive timeout, the value less than 0 means no timeout
getKeepAliveTime
(TimeUnit timeUnit)

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

public int
getMaxPoolSize()

Returns: the maxpoolsize

public MemoryManager<E extends Buffer>
public String
getPoolName()

Returns: the poolname

public int
public Queue<Runnable>
getQueue()

Returns: the queue

public int
getQueueLimit()

Returns: the thread-pool queue limit.

public ThreadFactory

Returns:

the threadFactory
getThreadFactory
()

Returns ThreadFactory.

public DelayedExecutor
public long
public boolean
public ThreadPoolConfig
setCorePoolSize(int
the core thread pool size
corePoolSize
)

Returns: the ThreadPoolConfig with the new core pool size

public ThreadPoolConfig
setDaemon(boolean isDaemon)

public ThreadPoolConfig

Returns:

the ThreadPoolConfig
setInitialClassLoader
(final ClassLoader
the classloader to be exposed by threads of this pool.
initialClassLoader
)

Specifies the context classloader 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
setMaxPoolSize(int
the max thread pool size
maxPoolSize
)

Returns: the ThreadPoolConfig with the new max pool size

public ThreadPoolConfig
public ThreadPoolConfig
setPoolName(String
the thread pool name.
poolname
)

Returns: the ThreadPoolConfig with the new thread pool name.

public ThreadPoolConfig
setPriority(int priority)

public ThreadPoolConfig
setQueue(Queue<Runnable>
the queue implemenation to use
queue
)

Returns: the ThreadPoolConfig with the new Queue implementation.

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

Returns: the ThreadPoolConfig with the new queue limite

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

Returns: the ThreadPoolConfig with the new ThreadFactory

public ThreadPoolConfig
setTransactionMonitor(final DelayedExecutor transactionMonitor)

public ThreadPoolConfig
setTransactionTimeout(final long transactionTimeout, final TimeUnit timeunit)

public ThreadPoolConfig
setTransactionTimeout(final DelayedExecutor transactionMonitor, final long transactionTimeout, final TimeUnit timeunit)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

corePoolSizeback to summary
protected int corePoolSize
DEFAULTback to summary
private static final ThreadPoolConfig DEFAULT
initialClassLoaderback to summary
protected ClassLoader initialClassLoader
isDaemonback to summary
protected boolean isDaemon
keepAliveTimeMillisback to summary
protected long keepAliveTimeMillis
maxPoolSizeback to summary
protected int maxPoolSize
mmback to summary
protected MemoryManager<E extends Buffer> mm
poolNameback to summary
protected String poolName
priorityback to summary
protected int priority
queueback to summary
protected Queue<Runnable> queue
queueLimitback to summary
protected int queueLimit
threadFactoryback to summary
protected ThreadFactory threadFactory
threadPoolMonitoringConfigback to summary
protected final DefaultMonitoringConfig<ThreadPoolProbe> threadPoolMonitoringConfig

Thread pool probes

transactionMonitorback to summary
protected DelayedExecutor transactionMonitor
transactionTimeoutMillisback to summary
protected long transactionTimeoutMillis

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, MemoryManager<E extends Buffer> mm, DelayedExecutor transactionMonitor, long transactionTimeoutMillis, ClassLoader initialClassLoader)
ThreadPoolConfigback to summary
private ThreadPoolConfig(ThreadPoolConfig cfg)

Method Detail

copyback to summary
public ThreadPoolConfig copy()
defaultConfigback to summary
public static ThreadPoolConfig defaultConfig()

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

Returns:ThreadPoolConfig

the Grizzly thread-pool configuration instance.

getCorePoolSizeback to summary
public int getCorePoolSize()
Returns:int

the corepoolsize

getInitialClassLoaderback to summary
public ClassLoader getInitialClassLoader()
Returns:ClassLoader

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

Since
2.3
getInitialMonitoringConfigback to summary
public DefaultMonitoringConfig<ThreadPoolProbe> getInitialMonitoringConfig()
getKeepAliveTimeback to summary
public long getKeepAliveTime(TimeUnit timeUnit)

Returns 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.

Returns:long

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

getMaxPoolSizeback to summary
public int getMaxPoolSize()
Returns:int

the maxpoolsize

getMemoryManagerback to summary
public MemoryManager<E extends Buffer> getMemoryManager()
getPoolNameback to summary
public String getPoolName()
Returns:String

the poolname

getPriorityback to summary
public int getPriority()
getQueueback to summary
public Queue<Runnable> getQueue()
Returns:Queue<Runnable>

the queue

getQueueLimitback to summary
public int getQueueLimit()
Returns:int

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

getThreadFactoryback to summary
public ThreadFactory getThreadFactory()

Returns ThreadFactory. If ThreadFactory is set - then priority, isDaemon, poolName settings will not be considered when creating new threads.

Returns:ThreadFactory

the threadFactory

getTransactionMonitorback to summary
public DelayedExecutor getTransactionMonitor()
getTransactionTimeoutback to summary
public long getTransactionTimeout(final TimeUnit timeUnit)
isDaemonback to summary
public boolean isDaemon()
setCorePoolSizeback to summary
public ThreadPoolConfig setCorePoolSize(int corePoolSize)
Parameters
corePoolSize:int

the core thread pool size

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new core pool size

setDaemonback to summary
public ThreadPoolConfig setDaemon(boolean isDaemon)
setInitialClassLoaderback to summary
public ThreadPoolConfig setInitialClassLoader(final ClassLoader initialClassLoader)

Specifies the context classloader that will be used by threads in this pool. If not specified, the classloader of the parent thread that initialized the pool will be used.

Parameters
initialClassLoader:ClassLoader

the classloader to be exposed by threads of this pool.

Returns:ThreadPoolConfig

the ThreadPoolConfig

Since
2.3
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.

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)
Parameters
maxPoolSize:int

the max thread pool size

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new max pool size

setMemoryManagerback to summary
public ThreadPoolConfig setMemoryManager(MemoryManager<E extends Buffer> mm)
setPoolNameback to summary
public ThreadPoolConfig setPoolName(String poolname)
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)
setQueueback to summary
public ThreadPoolConfig setQueue(Queue<Runnable> queue)
Parameters
queue:Queue<Runnable>

the queue implemenation to use

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new Queue implementation.

setQueueLimitback to summary
public ThreadPoolConfig setQueueLimit(int queueLimit)
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 limite

setThreadFactoryback to summary
public ThreadPoolConfig setThreadFactory(ThreadFactory threadFactory)
Parameters
threadFactory:ThreadFactory

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

Returns:ThreadPoolConfig

the ThreadPoolConfig with the new ThreadFactory

setTransactionMonitorback to summary
public ThreadPoolConfig setTransactionMonitor(final DelayedExecutor transactionMonitor)
setTransactionTimeoutback to summary
public ThreadPoolConfig setTransactionTimeout(final long transactionTimeout, final TimeUnit timeunit)
setTransactionTimeoutback to summary
public ThreadPoolConfig setTransactionTimeout(final DelayedExecutor transactionMonitor, final long transactionTimeout, final TimeUnit timeunit)
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.

Annotations
@Override