biz.hammurapi.util
Class ThreadPool

java.lang.Object
  extended by biz.hammurapi.config.ComponentBase
      extended by biz.hammurapi.util.ThreadPool
All Implemented Interfaces:
Component, Context, MeasurementCollector, MeasurementConsumer, Worker

public class ThreadPool
extends ComponentBase
implements Worker

Distributes work among multiple threads.

Author:
Pavel Vlasov

Field Summary
 
Fields inherited from class biz.hammurapi.config.ComponentBase
owner
 
Constructor Summary
ThreadPool()
           
ThreadPool(int numberOfThreads, int priority, int maxQueue, ExceptionSink exceptionSink)
           
ThreadPool(int numberOfThreads, int priority, int maxQueue, ExceptionSink exceptionSink, java.lang.String name)
           
 
Method Summary
 int getMaxQueue()
           
 java.lang.String getName()
           
 int getNumberOfThreads()
           
 int getPriority()
           
 boolean post(java.lang.Runnable job)
          Gives job to worker
 void replenish()
          Creates threads to replace terminated threads.
 void setExceptionSink(ExceptionSink exceptionSink)
           
 void setMaxQueue(int maxQueue)
           
 void setName(java.lang.String name)
           
 void setNumberOfThreads(int numberOfThreads)
           
 void setPriority(int priority)
           
 void start()
          Invoked by container before the first use.
 void stop()
          Invoked by container when component is not needed anymore.
 
Methods inherited from class biz.hammurapi.config.ComponentBase
addMeasurement, get, getChild, getMeasurementConsumer, getOwner, getOwner, setMeasurementConsumer, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool()

ThreadPool

public ThreadPool(int numberOfThreads,
                  int priority,
                  int maxQueue,
                  ExceptionSink exceptionSink)
Parameters:
numberOfThreads - Number of threads to create.
priority - Threads priority.
maxQueue - Maximum number of jobs in execution queue. When execution queue reaches its maximum post() processes job in the invoking thread. Values <1 mean no limit.
exceptionSink -

ThreadPool

public ThreadPool(int numberOfThreads,
                  int priority,
                  int maxQueue,
                  ExceptionSink exceptionSink,
                  java.lang.String name)
Method Detail

post

public boolean post(java.lang.Runnable job)
Description copied from interface: Worker
Gives job to worker

Specified by:
post in interface Worker
Returns:
true if worker accepted job. There can be situations when worker cannot accept job. E.g. remote worker cannot accept non-serializable job.

start

public void start()
           throws ConfigurationException
Description copied from interface: Component
Invoked by container before the first use. Component shall perform initialization in this method.

Specified by:
start in interface Component
Throws:
ConfigurationException

replenish

public void replenish()
Creates threads to replace terminated threads. Client posting jobs to thread pool may implement liveness check routines and terminate pool threads in a job hangs. This method allows the client code to replenish the thread pool after termination of one of worker threads.


stop

public void stop()
          throws ConfigurationException
Description copied from interface: Component
Invoked by container when component is not needed anymore. Component shall perform cleanup in this method.

Specified by:
stop in interface Component
Throws:
ConfigurationException

getMaxQueue

public int getMaxQueue()

setMaxQueue

public void setMaxQueue(int maxQueue)

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

getNumberOfThreads

public int getNumberOfThreads()

setNumberOfThreads

public void setNumberOfThreads(int numberOfThreads)

getPriority

public int getPriority()

setPriority

public void setPriority(int priority)

setExceptionSink

public void setExceptionSink(ExceptionSink exceptionSink)


Copyright © 2003 Hammurapi Group. All Rights Reserved.