Class QueueingThreadPoolExecutor

All Implemented Interfaces:
Executor, ExecutorService

public class QueueingThreadPoolExecutor extends ThreadPoolExecutor
This is a thread pool executor service, which works as a developer would expect it to work. The default ThreadPoolExecutor does the following (see the official JavaDoc):
  • If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing.
  • If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread.
  • If a request cannot be queued, a new thread is created unless this would exceed maximumPoolSize, in which case, the task will be rejected.
This class in contrast implements the following logic:
  • corePoolSize is 1, so threads are only created on demand
  • If the number of busy threads is smaller than the threadPoolSize, the Executor always prefers adding (or reusing) a thread rather than queuing it.
  • If threadPoolSize threads are busy, new requests will be put in a FIFO queue and processed as soon as a thread becomes idle.
  • The queue size is unbound, i.e. requests will never be rejected.
  • Threads are terminated after being idle for at least 10 seconds.
Please note that this implementation (with its partially hard-coded settings) is specifically targeted for use on embedded devices without a high throughput. If you intend to use it for mass data processing on a server, you should definitely tweak those settings.
Kai Kreuzer - Initial contribution