A thread pool implementation in Java which tried to overcome one of the major shortcoming (in the author's opinion): reusing idle threads. There is actually a long-standing JDK enhancement about this issue.
The use case for this feature is the following: when a process requires to have many thread pools, each with a significant number of maximum (core) threads, we end up having (many) hundreds of threads laying around which will consume resources (memory).
Every task scheduled with the pool in the JDK implementation ends up creating a thread even if there are idle threads lying around. These threads will not be reclaimed until the timeout for core threads is reached (if enabled).
In addition to this specific (but important) enhancement, the thread pool aims to provide various feature to help writing multithread applications easier:
- TODO
Various interfaces are available to schedule task:
DelayedTask
can be executed and provides the delay to be executed onceScheduledTask
can be executed and provides the initial delay and the interval/delay to be executed periodicallySingletonTask
can be scheduled and only one instance matching a key will be kept in the queue