org.jboss.util.threadpool
Class BasicThreadPool

java.lang.Object
  extended byorg.jboss.util.threadpool.BasicThreadPool
All Implemented Interfaces:
BasicThreadPoolMBean (src) , ThreadPool (src) , ThreadPoolMBean (src)

public class BasicThreadPool
extends java.lang.Object
implements ThreadPool (src) , BasicThreadPoolMBean (src)

A basic thread pool.


Constructor Summary
BasicThreadPool()
          Create a new thread pool
BasicThreadPool(java.lang.String name)
          Create a new thread pool with a default queue size of 1024, min/max pool sizes of 100 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 (src)  wrapper)
          Execute a task
protected  void executeOnThread(TaskWrapper (src)  wrapper)
          Execute a task on the same thread
 BlockingMode (src) getBlockingMode()
           
 ThreadPool (src) getInstance()
          Get the instance
 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
 java.lang.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
 java.lang.String getThreadGroupName()
          Retrieve the thread group name
 void run(java.lang.Runnable runnable)
          Run a runnable
 void run(java.lang.Runnable runnable, long startTimeout, long completeTimeout)
           
 void runTask(Task (src)  task)
          Run a task
 void runTaskWrapper(TaskWrapper (src)  wrapper)
          Run a task wrapper
 void setBlockingMode(BlockingMode (src)  mode)
          Set the behavior of the pool when a task is added and the queue is full.
 void setBlockingMode(java.lang.String name)
          For backward compatibility with the previous string based mode
 void setKeepAliveTime(long time)
          Set the keep alive time
 void setMaximumPoolSize(int size)
          Set the maximum pool size
 void setMaximumQueueSize(int size)
          Set the maximum queue size
 void setMinimumPoolSize(int size)
          Set the minimum pool size
 void setName(java.lang.String name)
          Set the thread pool name
 void setThreadGroupName(java.lang.String threadGroupName)
          Set the thread group name
 void stop()
          Stop the thread pool
 void stop(boolean immediate)
          Stop the pool
 java.lang.String toString()
           
protected  void waitForTask(TaskWrapper (src)  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(java.lang.String name)
Create a new thread pool with a default queue size of 1024, min/max pool sizes of 100 and a keep alive of 60 seconds.

Parameters:
name - the pool name
Method Detail

stop

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

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

waitForTasks

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

Specified by:
waitForTasks in interface ThreadPool (src)
Throws:
java.lang.InterruptedException

waitForTasks

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

Specified by:
waitForTasks in interface ThreadPool (src)
Parameters:
maxWaitTime -
Throws:
java.lang.InterruptedException

runTaskWrapper

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

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

runTask

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

Specified by:
runTask in interface ThreadPool (src)
Parameters:
task - the task

run

public void run(java.lang.Runnable runnable)
Description copied from interface: ThreadPool (src)
Run a runnable

Specified by:
run in interface ThreadPool (src)
Parameters:
runnable - the runnable

run

public void run(java.lang.Runnable runnable,
                long startTimeout,
                long completeTimeout)
Specified by:
run in interface ThreadPool (src)
Parameters:
runnable -
startTimeout -
completeTimeout -

getName

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

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

setName

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

Specified by:
setName in interface ThreadPoolMBean (src)
Parameters:
name - the name

getPoolNumber

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

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

getThreadGroupName

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

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

setThreadGroupName

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

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

getQueueSize

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

Specified by:
getQueueSize in interface BasicThreadPoolMBean (src)
Returns:
the queue size

getMaximumQueueSize

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

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

setMaximumQueueSize

public void setMaximumQueueSize(int size)
Description copied from interface: BasicThreadPoolMBean (src)
Set the maximum queue size

Specified by:
setMaximumQueueSize in interface BasicThreadPoolMBean (src)
Parameters:
size - the new maximum queue size

getPoolSize

public int getPoolSize()

getMinimumPoolSize

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

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

setMinimumPoolSize

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

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

getMaximumPoolSize

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

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

setMaximumPoolSize

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

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

getKeepAliveTime

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

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

setKeepAliveTime

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

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

getBlockingMode

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

setBlockingMode

public void setBlockingMode(BlockingMode (src)  mode)
Description copied from interface: BasicThreadPoolMBean (src)
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 (src)
Parameters:
mode - one of run, wait, discard, discardOldest or abort without regard to case.

setBlockingMode

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

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

getInstance

public ThreadPool (src)  getInstance()
Description copied from interface: ThreadPoolMBean (src)
Get the instance

Specified by:
getInstance in interface ThreadPoolMBean (src)

stop

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

Specified by:
stop in interface ThreadPoolMBean (src)

toString

public java.lang.String toString()

executeOnThread

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

Parameters:
wrapper - the task wrapper

execute

protected void execute(TaskWrapper (src)  wrapper)
Execute a task

Parameters:
wrapper - the task wrapper

waitForTask

protected void waitForTask(TaskWrapper (src)  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()