ThreadPool

Description

ThreadPool executes Tasks asynchronously, using long running daemon threads, or using worker threads from a pool of limited capacity.

Task is derived from Valve. The differences are that Task is named (base implementation uses derived class name for that), and that a long running Task may be asked to interrupt it's operation and terminate.

Tasks passed to runDaemon(Task) method are executed in a JVM daemon threads. It is considered an error condition if such tasks exits it's process(Context) method before terminate(Thread) method is called upon it.

Tasks passed to runWorker(Task) method are put into a FIFO queue. A special daemon Task - worker scheduler - picks them up and dispatches them using worker threads from a limited size pool. The tasks passed to runWorker(Task) should terminate in reasonable time, otherwise the pool will become exhausetd and the tasks will linger in the dispatch queue. The implementation does not detect nor attempt to fix this situation at this point.

The cleanup valve, passed to the ThreadPool's constructor is invoked whenever user supplied Task terminates. It may be used to perform cleanup and accounting as needed. Note that you may use SimplePipeline component to chain a few cleanup valves together.

Browse

Dependencies

required components Context, LoggerFactory, ConfigurationFactory
required libraries DNA API (dna:dna-api), commons-pool (commons-pool)

Constructor parameters

position type descritpion
1 org.objectledge.pipeline.Valve the cleanup Valve
2 org.objectledge.context.Context the thread's context
3 import org.jcontainer.dna.Configuration the pool configuration
4 import org.jcontainer.dna.Logger the logger