com.metamatrix.common.queue
Class WorkerPoolFactory

java.lang.Object
  extended by com.metamatrix.common.queue.WorkerPoolFactory

public class WorkerPoolFactory
extends java.lang.Object

Creates named, queued, daemon Thread pools.
The requirements are:

  1. minimize thread creation
  2. allow for proper timeout of idle threads
  3. allow for queuing

A non-fifo (lifo) SynchronousQueue based ThreadPoolExecutor satisfies 1 and 2, but not 3. A bounded or unbound queue based ThreadPoolExecutor allows for 3, but will tend to create up to the maximum number of threads and makes no guarantee on thread scheduling.
So the approach here is to use virtual thread pools off of single shared SynchronousQueue backed ThreadPoolExecutor.
There is also only a single master scheduling thread with actual executions deferred to the calling WorkerPool. TODO: this probably needs to be re-thought, especially since the lifo ordering of a SynchronousQueue is not guaranteed behavior. also there's a race condition between previously retiring threads and new work - prior to being returned to the shared pool we can create extra threads if the shared pool is exhausted. TODO: bounded queuing - we never bothered bounding in the past with our worker pools, but reasonable defaults would be a good idea.


Constructor Summary
WorkerPoolFactory()
           
 
Method Summary
static WorkerPool newWorkerPool(java.lang.String name, int numThreads)
          Creates a WorkerPool that prefers thread reuse over thread creation based upon the given parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkerPoolFactory

public WorkerPoolFactory()
Method Detail

newWorkerPool

public static WorkerPool newWorkerPool(java.lang.String name,
                                       int numThreads)
Creates a WorkerPool that prefers thread reuse over thread creation based upon the given parameters

Parameters:
name -
numThreads - the maximum number of worker threads allowed
Returns:


Copyright © 2009. All Rights Reserved.