...
Thread pools allow the system to service as many requests as it can comfortably sustain, instead of terminating all services when faced with a deluge of requests. They overcome these issues because the maximum number of worker threads that can be initiated and executed concurrently can be suitably controlled. Every worker accepts a Runnable
or Callable<T>
task and stores it in a temporary Channel
such as a buffer or a queue until resources become available. Because threads in a thread pool can be reused, and efficiently added and or removed from the Channel
, there is minimal thread life-cycle management related overhead is minimized.
Noncompliant Code Example
...
The interface ExecutorService
used in this compliant solution derives from the java.util.concurrent.Executor
interface and . The ExecutorService.submit()
method allows callers to also obtain a "future" (result of an asynchronous computation) . The caller can use the future that enables them to perform additional tasks functions such as task cancellation.
...