Java Reference
In-Depth Information
combines the header, body, and footer into the finished page. With a single-threaded execut-
or, ThreadDeadlock will always deadlock. Similarly, tasks coordinating amongst them-
selves with a barrier could also cause thread starvation deadlock if the pool is not big enough.
Whenever you submit to an Executor tasks that are not independent, be aware of the pos-
sibility of thread starvation deadlock, and document any pool sizing or configuration con-
straints in the code or configuration file where the Executor is configured.
In addition to any explicit bounds on the size of a thread pool, there may also be implicit
limits because of constraints on other resources. If your application uses a JDBC connection
pool with ten connections and each task needs a database connection, it is as if your thread
pool only has ten threads because tasks in excess of ten will block waiting for a connection.
Listing 8.1. Task that Deadlocks in a Single-threaded Executor . Don't do this.
8.1.2. Long-running Tasks
Thread pools can have responsiveness problems if tasks can block for extended periods of
time, even if deadlock is not a possibility. A thread pool can become clogged with long-run-
ning tasks, increasing the service time even for short tasks. If the pool size is too small relat-
ive to the expected steady-state number of longrunning tasks, eventually all the pool threads
will be running long-running tasks and responsiveness will suffer.
Search WWH ::




Custom Search