Livelock – Concurrency: Part I

Livelock Two threads may result in a livelock, if the response by a thread to another thread’s action is always to undo or revert the consequences of the action. The threads are responding to each other, but are blocked in making any progress. The combined actions of the threads make it impossible for them to

The Executor Framework – Concurrency: Part II

23.2 The Executor Framework Executors provide a high-level approach to launching tasks and managing threads. Tasks are executed asynchronously by threads in a multithreaded environment, where a task defines a unit of work—that is, a task is a set of instructions executed by a thread. Internally, an executor maintains a thread pool that utilizes a

Using an Executor Service 2 – Concurrency: Part II

When the executor service is no longer needed, it should be closed properly so that resources associated with the executor service can be reclaimed. As an executor service is not AutoCloseable, we cannot use the try-with-resources statement. The simplest shutdown procedure involves either calling the shutdown() or shutdownNow() method for this purpose. Calling either of

Using an Executor Service – Concurrency: Part II

Using an Executor Service The idiom for using an executor service is embodied in the following steps that are illustrated in Example 23.1: • Create the executor service. • Submit tasks to the executor service. • Shut down and terminate the executor service. Example 23.1 Executor Lifecycle Click here to view code image package executors;import
BACK TO TOP