JBoss Common Classes 2.2.17.GA

org.jboss.util.threadpool
Class BasicThreadPool

java.lang.Object
  extended by org.jboss.util.threadpool.BasicThreadPool
All Implemented Interfaces:
BasicThreadPoolMBean, ThreadPool, ThreadPoolMBean

public class BasicThreadPool
extends Object
implements ThreadPool, BasicThreadPoolMBean

A basic thread pool. TODO: this port to jdk concurrent still needs to be tested.

Version:
$Revision: 2892 $
Author:
Adrian Brock, Scott.Stark@jboss.org

Constructor Summary
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.
 
Method Summary
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()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicThreadPool

public BasicThreadPool()
Create a new thread pool


BasicThreadPool

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

Parameters:
name - the pool name

BasicThreadPool

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

Parameters:
name - the pool name
threadGroup - threadGroup
Method Detail

stop

public void stop(boolean immediate)
Description copied from interface: ThreadPool
Stop the pool

Specified by:
stop in interface ThreadPool
Parameters:
immediate - whether to shutdown immediately

waitForTasks

public void waitForTasks()
                  throws InterruptedException
Description copied from interface: ThreadPool
Wait on the queued tasks to complete. This can only be called after stop.

Specified by:
waitForTasks in interface ThreadPool
Throws:
InterruptedException - for any iterruption error

waitForTasks

public void waitForTasks(long maxWaitTime)
                  throws InterruptedException
Description copied from interface: ThreadPool
Wait on the queued tasks to complete upto maxWaitTime milliseconds. This can only be called after stop.

Specified by:
waitForTasks in interface ThreadPool
Parameters:
maxWaitTime - the max wait time
Throws:
InterruptedException - for any interruption error

runTaskWrapper

public void runTaskWrapper(TaskWrapper wrapper)
Description copied from interface: ThreadPool
Run a task wrapper

Specified by:
runTaskWrapper in interface ThreadPool
Parameters:
wrapper - the task wrapper

runTask

public void runTask(Task task)
Description copied from interface: ThreadPool
Run a task

Specified by:
runTask in interface ThreadPool
Parameters:
task - the task

run

public void run(Runnable runnable)
Description copied from interface: ThreadPool
Run a runnable

Specified by:
run in interface ThreadPool
Parameters:
runnable - the runnable

run

public void run(Runnable runnable,
                long startTimeout,
                long completeTimeout)
Description copied from interface: ThreadPool
Run runnable with start and complete time out set explicitely.

Specified by:
run in interface ThreadPool
Parameters:
runnable - the runnable
startTimeout - the start timeout
completeTimeout - the complete timeout

getThreadGroup

public ThreadGroup getThreadGroup()

getName

public String getName()
Description copied from interface: ThreadPoolMBean
Get the thread pool name

Specified by:
getName in interface ThreadPoolMBean
Returns:
the thread pool name

setName

public void setName(String name)
Description copied from interface: ThreadPoolMBean
Set the thread pool name

Specified by:
setName in interface ThreadPoolMBean
Parameters:
name - the name

getPoolNumber

public int getPoolNumber()
Description copied from interface: ThreadPoolMBean
Get the internal pool number

Specified by:
getPoolNumber in interface ThreadPoolMBean
Returns:
the internal pool number

getThreadGroupName

public String getThreadGroupName()
Description copied from interface: BasicThreadPoolMBean
Retrieve the thread group name

Specified by:
getThreadGroupName in interface BasicThreadPoolMBean
Returns:
the thread group name

setThreadGroupName

public void setThreadGroupName(String threadGroupName)
Description copied from interface: BasicThreadPoolMBean
Set the thread group name

Specified by:
setThreadGroupName in interface BasicThreadPoolMBean
Parameters:
threadGroupName - - the thread group name

getQueueSize

public int getQueueSize()
Description copied from interface: BasicThreadPoolMBean
Get the current queue size

Specified by:
getQueueSize in interface BasicThreadPoolMBean
Returns:
the queue size

getMaximumQueueSize

public int getMaximumQueueSize()
Description copied from interface: BasicThreadPoolMBean
Get the maximum queue size

Specified by:
getMaximumQueueSize in interface BasicThreadPoolMBean
Returns:
the maximum queue size

setMaximumQueueSize

public void setMaximumQueueSize(int size)
This resets the work queue capacity. This requires recreating the work queue and ThreadPoolExecutor, so this needs to be called before doing any work with the pool.

Specified by:
setMaximumQueueSize in interface BasicThreadPoolMBean
Parameters:
size - new work queue capacity

getPoolSize

public int getPoolSize()

getMinimumPoolSize

public int getMinimumPoolSize()
Description copied from interface: ThreadPoolMBean
Get the minimum pool size

Specified by:
getMinimumPoolSize in interface ThreadPoolMBean
Returns:
the minimum pool size

setMinimumPoolSize

public void setMinimumPoolSize(int size)
Description copied from interface: ThreadPoolMBean
Set the minimum pool size

Specified by:
setMinimumPoolSize in interface ThreadPoolMBean
Parameters:
size - the minimum pool size

getMaximumPoolSize

public int getMaximumPoolSize()
Description copied from interface: ThreadPoolMBean
Get the maximum pool size

Specified by:
getMaximumPoolSize in interface ThreadPoolMBean
Returns:
the maximum pool size

setMaximumPoolSize

public void setMaximumPoolSize(int size)
Description copied from interface: ThreadPoolMBean
Set the maximum pool size

Specified by:
setMaximumPoolSize in interface ThreadPoolMBean
Parameters:
size - the maximum pool size

getKeepAliveTime

public long getKeepAliveTime()
Description copied from interface: BasicThreadPoolMBean
Get the keep alive time

Specified by:
getKeepAliveTime in interface BasicThreadPoolMBean
Returns:
the keep alive time

setKeepAliveTime

public void setKeepAliveTime(long time)
Description copied from interface: BasicThreadPoolMBean
Set the keep alive time

Specified by:
setKeepAliveTime in interface BasicThreadPoolMBean
Parameters:
time - the keep alive time

getBlockingMode

public BlockingMode getBlockingMode()
Specified by:
getBlockingMode in interface BasicThreadPoolMBean
Returns:
the blocking mode

setBlockingMode

public void setBlockingMode(BlockingMode mode)
Description copied from interface: BasicThreadPoolMBean
Set the behavior of the pool when a task is added and the queue is full. The mode string indicates one of the following modes: abort - a RuntimeException is thrown run - the calling thread executes the task wait - the calling thread blocks until the queue has room discard - the task is silently discarded without being run discardOldest - check to see if a task is about to complete and enque the new task if possible, else run the task in the calling thread

Specified by:
setBlockingMode in interface BasicThreadPoolMBean
Parameters:
mode - one of run, wait, discard, discardOldest or abort without regard to case.

setBlockingMode

public void setBlockingMode(String name)
For backward compatibility with the previous string based mode

Parameters:
name - - the string form of the mode enum

setBlockingModeString

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

Parameters:
name - - the string form of the mode enum

getClassLoaderSource

public ClassLoaderSource getClassLoaderSource()
Description copied from interface: BasicThreadPoolMBean
Gets the source of the classloader that will be set as the thread context classloader for pool threads.

Specified by:
getClassLoaderSource in interface BasicThreadPoolMBean
Returns:
the ClassLoaderSource. May return null.

setClassLoaderSource

public void setClassLoaderSource(ClassLoaderSource classLoaderSource)
Description copied from interface: BasicThreadPoolMBean
Sets the source of the classloader that will be set as the thread 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.

Specified by:
setClassLoaderSource in interface BasicThreadPoolMBean
Parameters:
classLoaderSource - the ClassLoaderSource. May be null.

getInstance

public ThreadPool getInstance()
Specified by:
getInstance in interface ThreadPoolMBean
Returns:
the instance

stop

public void stop()
Description copied from interface: ThreadPoolMBean
Stop the thread pool

Specified by:
stop in interface ThreadPoolMBean

toString

public String toString()
Overrides:
toString in class Object

executeOnThread

protected void executeOnThread(TaskWrapper wrapper)
Execute a task on the same thread

Parameters:
wrapper - the task wrapper

execute

protected void execute(TaskWrapper wrapper)
Execute a task

Parameters:
wrapper - the task wrapper

waitForTask

protected void waitForTask(TaskWrapper wrapper)
Wait for a task

Parameters:
wrapper - the task wrapper

checkTimeoutMonitor

protected void checkTimeoutMonitor()
Used to lazily create the task completion timeout thread and monitor


getNextTimeout

protected org.jboss.util.threadpool.BasicThreadPool.TimeoutInfo getNextTimeout()

setDefaultThreadContextClassLoader

protected void setDefaultThreadContextClassLoader(Thread thread)

JBoss Common Classes 2.2.17.GA

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.