org.openeai.threadpool
Interface ThreadPool

All Known Implementing Classes:
ThreadPoolImpl

public interface ThreadPool


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.
 

Method Detail

addJob

void addJob(java.lang.Runnable job)
            throws ThreadPoolException
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.

Parameters:
job - java.lang.Runnable the job to be added to the ThreadPool
Throws:
- - ThreadPoolException if it has any problems adding the job to the ThreadPool.
ThreadPoolException
See Also:
checkBeforeProcessing()

getStats

Stats getStats()
Takes a "snapshot" of the threadpool at the current time and returns statistics.

Returns:
Stats
See Also:
Stats

getJobsInProgress

int getJobsInProgress()
Returns the number of jobs that are currently in progress for this ThreadPool.

Returns:
int the number of jobs in progress (available threads - idle threads)

checkBeforeProcessing

boolean checkBeforeProcessing()
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.

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


Copyright © 2002,2003 OpenEAI Software Foundation