Java Reference
In-Depth Information
is created through one of the factory methods in
Executors
(except
newSingleThreadExecutor
), you can cast the result to
Thread-PoolExecutor
to
access the setters as in
Listing 8.8
.
Executors
includes a factory method,
unconfigurableExecutorService
, which
takes an existing
ExecutorService
and wraps it with one exposing only the methods of
ExecutorService
so it cannot be further configured. Unlike the pooled implementations,
newSingleThreadExecutor
returns an
ExecutorService
wrapped in this manner,
rather than a raw
ThreadPoolExecutor
. While a single-threaded executor is actually
implemented as a thread pool with one thread, it also promises not to execute tasks concur-
rently. If some misguided code were to increase the pool size on a single-threaded executor,
it would undermine the intended execution semantics.