biz.hammurapi.util
Class ThreadPool
java.lang.Object
biz.hammurapi.config.ComponentBase
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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)
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.