ariba.util.core
Class ThreadPool

java.lang.Object
  extended by ariba.util.core.ThreadPool
All Implemented Interfaces:
Executor

public class ThreadPool
extends java.lang.Object
implements Executor

Standard non-extensible thread pool implememtation on top of queue. Users provide Runnable implementations and call execute.

The pool is constituted of Threads retrieve from a ThreadFactory. Normally, the number of threads created cannot exceed a specified number of threads, and new threads are created if necessary until the limit is reached.

Each thread pool is configured with a RejectedExecutionHandler. When the user call execute, the runnable is added to a queue and a thread is notified. If all threads are busy, then one will be added until the thread size limit is reached. When this happens, outstanding runnables are queued up. When the queue reaches its (configurable) capacity, the RejectedExecutionHandler will be called upon to handle the situation.

At present there are 2 handlers:

Pooled threads remaining idle for longer than the specified time out, will be terminated. A timeout of 0 will result in no idle threads being terminated.

Based on the above discussion, we can arrive at the following guidelines:


Constructor Summary
ThreadPool(java.lang.String name, ThreadManager threadManager)
          Creates a new ThreadPool starting 1 thread and containing up to 5 threads.
ThreadPool(java.lang.String name, ThreadManager threadManager, int minThreads, int maxThreads, long timeout, int queueCapacity, java.lang.String handlerClassName)
          Creates a new ThreadPool.
 
Method Summary
 void execute(java.lang.Runnable command)
          Retrieves a thread from the pool and have it execute the given runnable.
 int getMaxThreadCount()
          Returns the configured max thread limit.
 ThreadPoolMonitor getMonitor()
           
 int getQueueSize()
          Returns the number of objects waiting in the queue
 int getThreadCount()
          Returns the size of the ThreadPool
 void setMonitor(ThreadPoolMonitor monitor)
          not synchronized, last one wins
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(java.lang.String name,
                  ThreadManager threadManager)
Creates a new ThreadPool starting 1 thread and containing up to 5 threads. Threads die after 30 minutes of inactivity.

Parameters:
name - the name used for the threads
threadManager - the ThreadManager used to manage the threads

ThreadPool

public ThreadPool(java.lang.String name,
                  ThreadManager threadManager,
                  int minThreads,
                  int maxThreads,
                  long timeout,
                  int queueCapacity,
                  java.lang.String handlerClassName)
Creates a new ThreadPool.

Parameters:
name - the name used for the threads
threadManager - the ThreadManager used to manage the threads
minThreads - the number of threads to start with
maxThreads - the maximum number of threads managed by the pool
timeout - the maximum time a thread remains inactive
queueCapacity - the size of the queue to hold the runnables. Note that it is possible for the queue to grow beyond this initial capacity.
handlerClassName - the name of the handling class. If null DefaultRejectedExecutionHandler will be used.
Method Detail

execute

public void execute(java.lang.Runnable command)
Retrieves a thread from the pool and have it execute the given runnable.

Specified by:
execute in interface Executor
Parameters:
command - the task to be executed
Throws:
RejectedExecutionException - if the execution is rejected.

setMonitor

public void setMonitor(ThreadPoolMonitor monitor)
not synchronized, last one wins


getMonitor

public ThreadPoolMonitor getMonitor()

getThreadCount

public int getThreadCount()
Returns the size of the ThreadPool


getQueueSize

public int getQueueSize()
Returns the number of objects waiting in the queue


getMaxThreadCount

public int getMaxThreadCount()
Returns the configured max thread limit.

Returns:


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.