Package org.teiid.dqp.internal.process
Class ThreadReuseExecutor
- java.lang.Object
-
- org.teiid.dqp.internal.process.ThreadReuseExecutor
-
- All Implemented Interfaces:
Executor
,TeiidExecutor
public class ThreadReuseExecutor extends Object implements TeiidExecutor
An Executor that:- minimizes thread creation
- allows for proper timeout of idle threads
- allows for queuing
A non-fifo (lifo)SynchronousQueue
basedThreadPoolExecutor
satisfies 1 and 2, but not 3. A bounded or unbound queue basedThreadPoolExecutor
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 aSynchronousQueue
backedThreadPoolExecutor
.
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. TODO: aForkJoinPool
is a simple replacement, but we'd loose the prioritization queue.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadReuseExecutor.PrioritizedRunnable
static class
ThreadReuseExecutor.RunnableWrapper
-
Constructor Summary
Constructors Constructor Description ThreadReuseExecutor(String name, int maximumPoolSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
void
execute(Runnable command)
int
getActiveCount()
long
getCompletedCount()
int
getLargestPoolSize()
int
getQueued()
WorkerPoolStatisticsMetadata
getStats()
long
getSubmittedCount()
boolean
isTerminated()
protected void
logWaitMessage(long warnTime, int maximumPoolSize, String poolName, int highestQueueSize)
void
shutdown()
List<Runnable>
shutdownNow()
-
-
-
Constructor Detail
-
ThreadReuseExecutor
public ThreadReuseExecutor(String name, int maximumPoolSize)
-
-
Method Detail
-
execute
public void execute(Runnable command)
- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTeiidExecutor
-
logWaitMessage
protected void logWaitMessage(long warnTime, int maximumPoolSize, String poolName, int highestQueueSize)
-
getActiveCount
public int getActiveCount()
- Specified by:
getActiveCount
in interfaceTeiidExecutor
-
getSubmittedCount
public long getSubmittedCount()
-
getCompletedCount
public long getCompletedCount()
-
isTerminated
public boolean isTerminated()
-
shutdown
public void shutdown()
-
getLargestPoolSize
public int getLargestPoolSize()
-
getQueued
public int getQueued()
- Specified by:
getQueued
in interfaceTeiidExecutor
-
getStats
public WorkerPoolStatisticsMetadata getStats()
- Specified by:
getStats
in interfaceTeiidExecutor
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceTeiidExecutor
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceTeiidExecutor
- Throws:
InterruptedException
-
-