org.openeai.threadpool
Class ThreadPoolImpl


java.lang.Object

  |

  +--org.openeai.threadpool.ThreadPoolImpl

All Implemented Interfaces:
ThreadPool

public class ThreadPoolImpl
extends java.lang.Object
implements ThreadPool


Constructor Summary
ThreadPoolImpl(java.util.Properties props)
           
ThreadPoolImpl(ThreadPoolConfig tConfig)
           
 
Method Summary
 void addJob(java.lang.Runnable job)
          Adds a 'job' to the ThreadPool to be executed in a Thread.
 boolean checkBeforeProcessing()
          Returns a flag indicating whether this ThreadPool should check itself before adding another job to the pool.
 int getJobsInProgress()
          Returns the number of jobs that are currently in progress for this ThreadPool.
 Stats getStats()
          Takes a "snapshot" of the threadpool at the current time and returns statistics.
 void shutdown()
          Sets a flag indicating that the ThreadPool is in a 'shutdown' status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPoolImpl


public ThreadPoolImpl(ThreadPoolConfig tConfig)
               throws java.lang.NumberFormatException,
                      java.lang.IllegalArgumentException

ThreadPoolImpl


public ThreadPoolImpl(java.util.Properties props)
               throws java.lang.NumberFormatException,
                      java.lang.IllegalArgumentException
Method Detail

checkBeforeProcessing


public boolean checkBeforeProcessing()
Description copied from interface: ThreadPool
Returns a flag indicating whether this ThreadPool should check itself before adding another job to the pool. Based on this flag, if the thread pool can't find an idle thread and it can't create a new one because the maximum number of threads have already been allocated, it may or may not add the job to the list of "pending" jobs.

This is used to verify that the ThreadPool can actually accept and immediately process a job that's added via the addJob method. This is to reduce the number of potential jobs in memory in a "pending" state waiting for the ThreadPool to free up some idle threads.

Specified by:
checkBeforeProcessing in interface ThreadPool
Returns:
boolean true=make sure there's room in the pool before adding to the list of pending jobs.

shutdown


public void shutdown()
Sets a flag indicating that the ThreadPool is in a 'shutdown' status. No more jobs can be added to the pool when this happens.


addJob


public void addJob(java.lang.Runnable job)
            throws ThreadPoolException
Description copied from interface: ThreadPool
Adds a 'job' to the ThreadPool to be executed in a Thread. If the maximum number of threads for this pool has not been reached and an idle thread can't be found, this method will create a new thread and run the job in that thread. If it can't find an idle thread and it can't create a new one, it will check to see if it is allowed to add the job to a Vector of "pending" jobs so the job will be ran when there is room in the pool. If it is not allowed to add jobs to the Vector of pending jobs, it will throw an exception.

Specified by:
addJob in interface ThreadPool
ThreadPoolException
See Also:
ThreadPool.checkBeforeProcessing()

getStats


public Stats getStats()
Description copied from interface: ThreadPool
Takes a "snapshot" of the threadpool at the current time and returns statistics.

Specified by:
getStats in interface ThreadPool
Returns:
Stats
See Also:
Stats

getJobsInProgress


public int getJobsInProgress()
Description copied from interface: ThreadPool
Returns the number of jobs that are currently in progress for this ThreadPool.

Specified by:
getJobsInProgress in interface ThreadPool
Returns:
int the number of jobs in progress (available threads - idle threads)


Copyright © 2002, OpenEAI Software Foundation