org.teiid.dqp.internal.process
Class ThreadReuseExecutor

java.lang.Object
  extended by org.teiid.dqp.internal.process.ThreadReuseExecutor
All Implemented Interfaces:
java.util.concurrent.Executor

public class ThreadReuseExecutor
extends java.lang.Object
implements java.util.concurrent.Executor

An Executor that:

  1. minimizes thread creation
  2. allows for proper timeout of idle threads
  3. allows 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 a virtual thread pool off of a SynchronousQueue backed ThreadPoolExecutor.
There is also only a single master scheduling thread with actual executions deferred. TODO: there is a race condition between retiring threads and adding work, which may create extra threads. That is a flaw with attempting to reuse, rather than create threads. TODO: bounded queuing - we never bothered bounding in the past with our worker pools, but reasonable defaults would be a good idea.


Nested Class Summary
static interface ThreadReuseExecutor.PrioritizedRunnable
           
 
Constructor Summary
ThreadReuseExecutor(java.lang.String name, int maximumPoolSize)
           
 
Method Summary
 boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
           
 void execute(java.lang.Runnable command)
           
 int getActiveCount()
           
 int getCompletedCount()
           
 int getLargestPoolSize()
           
 int getPoolSize()
           
 WorkerPoolStatisticsMetadata getStats()
           
 int getSubmittedCount()
           
 boolean hasWork()
           
 boolean isTerminated()
           
 java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
           
 java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
           
 void shutdown()
           
 java.util.List<java.lang.Runnable> shutdownNow()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadReuseExecutor

public ThreadReuseExecutor(java.lang.String name,
                           int maximumPoolSize)
Method Detail

execute

public void execute(java.lang.Runnable command)
Specified by:
execute in interface java.util.concurrent.Executor

getActiveCount

public int getActiveCount()

getSubmittedCount

public int getSubmittedCount()

getCompletedCount

public int getCompletedCount()

getPoolSize

public int getPoolSize()

isTerminated

public boolean isTerminated()

shutdown

public void shutdown()

getLargestPoolSize

public int getLargestPoolSize()

getStats

public WorkerPoolStatisticsMetadata getStats()

hasWork

public boolean hasWork()

shutdownNow

public java.util.List<java.lang.Runnable> shutdownNow()

awaitTermination

public boolean awaitTermination(long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

schedule

public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
                                                        long delay,
                                                        java.util.concurrent.TimeUnit unit)

scheduleAtFixedRate

public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command,
                                                                   long initialDelay,
                                                                   long period,
                                                                   java.util.concurrent.TimeUnit unit)


Copyright © 2011. All Rights Reserved.