public class BasicThreadPool extends Object implements ThreadPool, BasicThreadPoolMBean
| Constructor and Description |
|---|
BasicThreadPool()
Create a new thread pool
|
BasicThreadPool(String name)
Create a new thread pool with a default queue size of 1024, max pool
size of 100, min pool size of 4, and a keep alive of 60 seconds.
|
BasicThreadPool(String name,
ThreadGroup threadGroup)
Create a new thread pool with a default queue size of 1024, max pool
size of 100, min pool size of 4, and a keep alive of 60 seconds.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkTimeoutMonitor()
Used to lazily create the task completion timeout thread and monitor
|
protected void |
execute(TaskWrapper wrapper)
Execute a task
|
protected void |
executeOnThread(TaskWrapper wrapper)
Execute a task on the same thread
|
BlockingMode |
getBlockingMode() |
ClassLoaderSource |
getClassLoaderSource()
Gets the source of the classloader that will be set as the
thread context classloader
for pool threads. |
ThreadPool |
getInstance() |
long |
getKeepAliveTime()
Get the keep alive time
|
int |
getMaximumPoolSize()
Get the maximum pool size
|
int |
getMaximumQueueSize()
Get the maximum queue size
|
int |
getMinimumPoolSize()
Get the minimum pool size
|
String |
getName()
Get the thread pool name
|
protected org.jboss.util.threadpool.BasicThreadPool.TimeoutInfo |
getNextTimeout() |
int |
getPoolNumber()
Get the internal pool number
|
int |
getPoolSize()
Get the current pool size
|
int |
getQueueSize()
Get the current queue size
|
ThreadGroup |
getThreadGroup() |
String |
getThreadGroupName()
Retrieve the thread group name
|
void |
run(Runnable runnable)
Run a runnable
|
void |
run(Runnable runnable,
long startTimeout,
long completeTimeout)
Run runnable with start and complete time out set explicitely.
|
void |
runTask(Task task)
Run a task
|
void |
runTaskWrapper(TaskWrapper wrapper)
Run a task wrapper
|
void |
setBlockingMode(BlockingMode mode)
Set the behavior of the pool when a task is added and the queue is full.
|
void |
setBlockingMode(String name)
For backward compatibility with the previous string based mode
|
void |
setBlockingModeString(String name)
For backward compatibility with the previous string based mode
This is needed for microcontainer as it gets confused with overloaded
setters.
|
void |
setClassLoaderSource(ClassLoaderSource classLoaderSource)
Sets the source of the classloader that will be set as the
thread context classloader
for pool threads. |
protected void |
setDefaultThreadContextClassLoader(Thread thread) |
void |
setKeepAliveTime(long time)
Set the keep alive time
|
void |
setMaximumPoolSize(int size)
Set the maximum pool size
|
void |
setMaximumQueueSize(int size)
This resets the work queue capacity.
|
void |
setMinimumPoolSize(int size)
Set the minimum pool size
|
void |
setName(String name)
Set the thread pool name
|
void |
setThreadGroupName(String threadGroupName)
Set the thread group name
|
void |
stop()
Stop the thread pool
|
void |
stop(boolean immediate)
Stop the pool
|
String |
toString() |
protected void |
waitForTask(TaskWrapper wrapper)
Wait for a task
|
void |
waitForTasks()
Wait on the queued tasks to complete.
|
void |
waitForTasks(long maxWaitTime)
Wait on the queued tasks to complete upto maxWaitTime milliseconds.
|
public BasicThreadPool()
public BasicThreadPool(String name)
name - the pool namepublic BasicThreadPool(String name, ThreadGroup threadGroup)
name - the pool namethreadGroup - threadGrouppublic void stop(boolean immediate)
ThreadPoolstop in interface ThreadPoolimmediate - whether to shutdown immediatelypublic void waitForTasks()
throws InterruptedException
ThreadPoolwaitForTasks in interface ThreadPoolInterruptedException - for any iterruption errorpublic void waitForTasks(long maxWaitTime)
throws InterruptedException
ThreadPoolwaitForTasks in interface ThreadPoolmaxWaitTime - the max wait timeInterruptedException - for any interruption errorpublic void runTaskWrapper(TaskWrapper wrapper)
ThreadPoolrunTaskWrapper in interface ThreadPoolwrapper - the task wrapperpublic void runTask(Task task)
ThreadPoolrunTask in interface ThreadPooltask - the taskpublic void run(Runnable runnable)
ThreadPoolrun in interface ThreadPoolrunnable - the runnablepublic void run(Runnable runnable, long startTimeout, long completeTimeout)
ThreadPoolrun in interface ThreadPoolrunnable - the runnablestartTimeout - the start timeoutcompleteTimeout - the complete timeoutpublic ThreadGroup getThreadGroup()
public String getName()
ThreadPoolMBeangetName in interface ThreadPoolMBeanpublic void setName(String name)
ThreadPoolMBeansetName in interface ThreadPoolMBeanname - the namepublic int getPoolNumber()
ThreadPoolMBeangetPoolNumber in interface ThreadPoolMBeanpublic String getThreadGroupName()
BasicThreadPoolMBeangetThreadGroupName in interface BasicThreadPoolMBeanpublic void setThreadGroupName(String threadGroupName)
BasicThreadPoolMBeansetThreadGroupName in interface BasicThreadPoolMBeanthreadGroupName - - the thread group namepublic int getQueueSize()
BasicThreadPoolMBeangetQueueSize in interface BasicThreadPoolMBeanpublic int getMaximumQueueSize()
BasicThreadPoolMBeangetMaximumQueueSize in interface BasicThreadPoolMBeanpublic void setMaximumQueueSize(int size)
setMaximumQueueSize in interface BasicThreadPoolMBeansize - new work queue capacitypublic int getPoolSize()
ThreadPoolMBeangetPoolSize in interface ThreadPoolMBeanpublic int getMinimumPoolSize()
ThreadPoolMBeangetMinimumPoolSize in interface ThreadPoolMBeanpublic void setMinimumPoolSize(int size)
ThreadPoolMBeansetMinimumPoolSize in interface ThreadPoolMBeansize - the minimum pool sizepublic int getMaximumPoolSize()
ThreadPoolMBeangetMaximumPoolSize in interface ThreadPoolMBeanpublic void setMaximumPoolSize(int size)
ThreadPoolMBeansetMaximumPoolSize in interface ThreadPoolMBeansize - the maximum pool sizepublic long getKeepAliveTime()
BasicThreadPoolMBeangetKeepAliveTime in interface BasicThreadPoolMBeanpublic void setKeepAliveTime(long time)
BasicThreadPoolMBeansetKeepAliveTime in interface BasicThreadPoolMBeantime - the keep alive timepublic BlockingMode getBlockingMode()
getBlockingMode in interface BasicThreadPoolMBeanpublic void setBlockingMode(BlockingMode mode)
BasicThreadPoolMBeansetBlockingMode in interface BasicThreadPoolMBeanmode - one of run, wait, discard, discardOldest or abort without
regard to case.public void setBlockingMode(String name)
name - - the string form of the mode enumpublic void setBlockingModeString(String name)
name - - the string form of the mode enumpublic ClassLoaderSource getClassLoaderSource()
BasicThreadPoolMBeanthread context classloader
for pool threads.getClassLoaderSource in interface BasicThreadPoolMBeanClassLoaderSource. May return null.public void setClassLoaderSource(ClassLoaderSource classLoaderSource)
BasicThreadPoolMBeanthread context classloader
for pool threads. If set, whenever any new pool thread is created, it's
context classloader will be set to the loader provided by this source.
Further, when any thread is returned to the pool, its context classloader
will be reset to the loader provided by this source.
If set to null (the default), the pool will not attempt to
manage the context classloader for pool threads; instead a newly created
pool thread will inherit its context classloader from whatever thread
triggered the addition to the pool. A thread returned to the pool will
not have its context classloader changed from whatever it was.
setClassLoaderSource in interface BasicThreadPoolMBeanclassLoaderSource - the ClassLoaderSource. May be null.public ThreadPool getInstance()
getInstance in interface ThreadPoolMBeanpublic void stop()
ThreadPoolMBeanstop in interface ThreadPoolMBeanprotected void executeOnThread(TaskWrapper wrapper)
wrapper - the task wrapperprotected void execute(TaskWrapper wrapper)
wrapper - the task wrapperprotected void waitForTask(TaskWrapper wrapper)
wrapper - the task wrapperprotected void checkTimeoutMonitor()
protected org.jboss.util.threadpool.BasicThreadPool.TimeoutInfo getNextTimeout()
protected void setDefaultThreadContextClassLoader(Thread thread)
Copyright © 2015 JBoss by Red Hat. All rights reserved.