Class ThreadReuseExecutor

  • All Implemented Interfaces:
    Executor, TeiidExecutor

    public class ThreadReuseExecutor
    extends Object
    implements TeiidExecutor
    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. TODO: a ForkJoinPool is a simple replacement, but we'd loose the prioritization queue.