com.botbox.util
Class ThreadPool

java.lang.Object
  extended by com.botbox.util.ThreadPool

public final class ThreadPool
extends java.lang.Object

This class implements a thread pool for reusing threads. Since only a maximal number of threads may exist in the pool it is important that the threads in the pool is not absorbed by long duration tasks that drains the pool.

Version:
$Revision: 4088 $, $Date: 2008-04-11 19:13:08 -0500 (Fri, 11 Apr 2008) $
Author:
Joakim Eriksson (joakim.eriksson@botbox.com), Niclas Finne (niclas.finne@botbox.com), Sverker Janson (sverker.janson@botbox.com)

Constructor Summary
ThreadPool(java.lang.String name)
           
 
Method Summary
static ThreadPool getDefaultThreadPool()
           
 int getIdleThreads()
          Returns the current number of idle threads
static JobStatus getJobStatus()
           
 int getMaxIdleThreads()
           
 int getMaxThreads()
           
 int getMinThreads()
           
 java.lang.String getName()
           
 int getQueueSize()
           
 long getQueueTime()
           
static ThreadPool getThreadPool(java.lang.String name)
           
static java.util.Enumeration getThreadPools()
           
 int getThreads()
           
 java.lang.String getThreadStatus()
          Returns the status of all existing pool threads or null if no pool threads exists.
 java.lang.StringBuffer getThreadStatus(java.lang.StringBuffer sb)
           
 void invokeLater(java.lang.Runnable job)
          Invokes the specified job as soon as possible.
 void invokeLater(java.lang.Runnable job, java.lang.String description)
           
 boolean isDaemon()
           
 void setDaemon(boolean isDaemon)
           
 void setInterruptThreadsAfter(int milliSeconds)
          Sets the time after which a running job may be interrupted if it still has not finished.
 void setMaxIdleThreads(int maxIdleThreads)
           
 void setMaxThreads(int maxThreads)
           
 void setMinThreads(int minThreads)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(java.lang.String name)
Method Detail

getThreadPools

public static java.util.Enumeration getThreadPools()

getThreadPool

public static ThreadPool getThreadPool(java.lang.String name)

getDefaultThreadPool

public static ThreadPool getDefaultThreadPool()

getJobStatus

public static JobStatus getJobStatus()

getName

public java.lang.String getName()

getThreads

public int getThreads()

getIdleThreads

public int getIdleThreads()
Returns the current number of idle threads


getThreadStatus

public java.lang.String getThreadStatus()
Returns the status of all existing pool threads or null if no pool threads exists.


getThreadStatus

public java.lang.StringBuffer getThreadStatus(java.lang.StringBuffer sb)

isDaemon

public boolean isDaemon()

setDaemon

public void setDaemon(boolean isDaemon)

getMinThreads

public int getMinThreads()

setMinThreads

public void setMinThreads(int minThreads)

getMaxThreads

public int getMaxThreads()

setMaxThreads

public void setMaxThreads(int maxThreads)

getMaxIdleThreads

public int getMaxIdleThreads()

setMaxIdleThreads

public void setMaxIdleThreads(int maxIdleThreads)

setInterruptThreadsAfter

public void setInterruptThreadsAfter(int milliSeconds)
Sets the time after which a running job may be interrupted if it still has not finished. A time of 0 (default) means the jobs can run for unlimited time and will never be interrupted.

Parameters:
milliSeconds - the time after which a running job may be interrupted if it still has not finished.

getQueueSize

public int getQueueSize()

getQueueTime

public long getQueueTime()

invokeLater

public void invokeLater(java.lang.Runnable job)
Invokes the specified job as soon as possible. New threads are created if none is available in the thread pool.

Parameters:
job - the job to invoke

invokeLater

public void invokeLater(java.lang.Runnable job,
                        java.lang.String description)


Copyright © 2007-2009 Association for Trading Agent Research. All Rights Reserved.