Package org.glassfish.grizzly.threadpool
Class ThreadPoolConfig
- java.lang.Object
-
- org.glassfish.grizzly.threadpool.ThreadPoolConfig
-
public final class ThreadPoolConfig extends Object
Grizzly thread-pool configuration, which might be used to create and initialize a thread-pool viaGrizzlyExecutorService.createInstance(org.glassfish.grizzly.threadpool.ThreadPoolConfig)
. One can get a default Grizzly ThreadPoolConfig usingcopy()
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
-
-
Field Summary
Fields Modifier and Type Field Description protected int
corePoolSize
protected ClassLoader
initialClassLoader
protected boolean
isDaemon
protected long
keepAliveTimeMillis
protected int
maxPoolSize
protected MemoryManager
mm
protected String
poolName
protected int
priority
protected Queue<Runnable>
queue
protected int
queueLimit
protected ThreadFactory
threadFactory
protected DefaultMonitoringConfig<ThreadPoolProbe>
threadPoolMonitoringConfig
Thread pool probesprotected DelayedExecutor
transactionMonitor
protected long
transactionTimeoutMillis
-
Method Summary
-
-
-
Field Detail
-
poolName
protected String poolName
-
corePoolSize
protected int corePoolSize
-
maxPoolSize
protected int maxPoolSize
-
queueLimit
protected int queueLimit
-
keepAliveTimeMillis
protected long keepAliveTimeMillis
-
threadFactory
protected ThreadFactory threadFactory
-
priority
protected int priority
-
isDaemon
protected boolean isDaemon
-
mm
protected MemoryManager mm
-
transactionMonitor
protected DelayedExecutor transactionMonitor
-
transactionTimeoutMillis
protected long transactionTimeoutMillis
-
initialClassLoader
protected ClassLoader initialClassLoader
-
threadPoolMonitoringConfig
protected final DefaultMonitoringConfig<ThreadPoolProbe> threadPoolMonitoringConfig
Thread pool probes
-
-
Method Detail
-
defaultConfig
public static ThreadPoolConfig defaultConfig()
Create new Grizzly thread-pool configuration instance. The returned ThreadPoolConfig instance will be pre-configured with a default values.- Returns:
- the Grizzly thread-pool configuration instance.
-
copy
public ThreadPoolConfig copy()
-
setQueue
public ThreadPoolConfig setQueue(Queue<Runnable> queue)
- Parameters:
queue
- the queue implemenation to use- Returns:
- the
ThreadPoolConfig
with the newQueue
implementation.
-
getThreadFactory
public ThreadFactory getThreadFactory()
ReturnsThreadFactory
. IfThreadFactory
is set - thenpriority
,isDaemon
,poolName
settings will not be considered when creating new threads.- Returns:
- the threadFactory
-
setThreadFactory
public ThreadPoolConfig setThreadFactory(ThreadFactory threadFactory)
- 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 String getPoolName()
- Returns:
- the poolname
-
setPoolName
public ThreadPoolConfig setPoolName(String poolname)
- Parameters:
poolname
- the thread pool name.- Returns:
- the
ThreadPoolConfig
with the new thread pool name.
-
getPriority
public int getPriority()
-
setPriority
public ThreadPoolConfig setPriority(int priority)
-
isDaemon
public boolean isDaemon()
-
setDaemon
public ThreadPoolConfig setDaemon(boolean isDaemon)
-
getMaxPoolSize
public int getMaxPoolSize()
- Returns:
- the maxpoolsize
-
setMaxPoolSize
public ThreadPoolConfig setMaxPoolSize(int maxPoolSize)
- Parameters:
maxPoolSize
- the max thread pool size- Returns:
- the
ThreadPoolConfig
with the new max pool size
-
getCorePoolSize
public int getCorePoolSize()
- Returns:
- the corepoolsize
-
setCorePoolSize
public ThreadPoolConfig setCorePoolSize(int corePoolSize)
- Parameters:
corePoolSize
- the core thread pool size- Returns:
- the
ThreadPoolConfig
with the new core pool size
-
getQueueLimit
public int getQueueLimit()
- Returns:
- the thread-pool queue limit. The queue limit value less than 0 means unlimited queue.
-
setQueueLimit
public ThreadPoolConfig setQueueLimit(int queueLimit)
- Parameters:
queueLimit
- the thread-pool queue limit. The queueLimit value less than 0 means unlimited queue.- Returns:
- the
ThreadPoolConfig
with the new queue limite
-
setKeepAliveTime
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 (seesetCorePoolSize(int)
,setMaxPoolSize(int)
) - then the thread will be terminated and removed from the thread pool.- Parameters:
time
- max keep alive timeout. The value less than 0 means no timeoutunit
- time unit- Returns:
- the
ThreadPoolConfig
with the new keep alive time
-
getKeepAliveTime
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 (seesetCorePoolSize(int)
,setMaxPoolSize(int)
) - then the thread will be terminated and removed from the thread pool.- Returns:
- the keep-alive timeout, the value less than 0 means no timeout
-
getMemoryManager
public MemoryManager getMemoryManager()
-
setMemoryManager
public ThreadPoolConfig setMemoryManager(MemoryManager mm)
-
getInitialMonitoringConfig
public DefaultMonitoringConfig<ThreadPoolProbe> getInitialMonitoringConfig()
-
getTransactionMonitor
public DelayedExecutor getTransactionMonitor()
-
setTransactionMonitor
public ThreadPoolConfig setTransactionMonitor(DelayedExecutor transactionMonitor)
-
getTransactionTimeout
public long getTransactionTimeout(TimeUnit timeUnit)
-
setTransactionTimeout
public ThreadPoolConfig setTransactionTimeout(long transactionTimeout, TimeUnit timeunit)
-
setTransactionTimeout
public ThreadPoolConfig setTransactionTimeout(DelayedExecutor transactionMonitor, long transactionTimeout, TimeUnit timeunit)
-
getInitialClassLoader
public ClassLoader getInitialClassLoader()
- Returns:
- the classloader (if any) to be initially exposed by threads from this pool.
- Since:
- 2.3
-
setInitialClassLoader
public ThreadPoolConfig setInitialClassLoader(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
- the classloader to be exposed by threads of this pool.- Returns:
- the
ThreadPoolConfig
- Since:
- 2.3
- See Also:
Thread.getContextClassLoader()
-
-