PacktLib: Java 7 Concurrency Cookbook

Java 7 Concurrency Cookbook


About the Author

About the Reviewers


Thread Management


Creating and running a thread

Getting and setting thread information

Interrupting a thread

Controlling the interruption of a thread

Sleeping and resuming a thread

Waiting for the finalization of a thread

Creating and running a daemon thread

Processing uncontrolled exceptions in a thread

Using local thread variables

Grouping threads into a group

Processing uncontrolled exceptions in a group of threads

Creating threads through a factory

Basic Thread Synchronization


Synchronizing a method

Arranging independent attributes in synchronized classes

Using conditions in synchronized code

Synchronizing a block of code with a Lock

Synchronizing data access with read/write locks

Modifying Lock fairness

Using multiple conditions in a Lock

Thread Synchronization Utilities


Controlling concurrent access to a resource

Controlling concurrent access to multiple copies of a resource

Waiting for multiple concurrent events

Synchronizing tasks in a common point

Running concurrent phased tasks

Controlling phase change in concurrent phased tasks

Changing data between concurrent tasks

Thread Executors


Creating a thread executor

Creating a fixed-size thread executor

Executing tasks in an executor that returns a result

Running multiple tasks and processing the first result

Running multiple tasks and processing all the results

Running a task in an executor after a delay

Running a task in an executor periodically

Canceling a task in an executor

Controlling a task finishing in an executor

Separating the launching of tasks and the processing of their results in an executor

Controlling rejected tasks of an executor

Fork/Join Framework


Creating a Fork/Join pool

Joining the results of the tasks

Running tasks asynchronously

Throwing exceptions in the tasks

Canceling a task

Concurrent Collections


Using non-blocking thread-safe lists

Using blocking thread-safe lists

Using blocking thread-safe lists ordered by priority

Using thread-safe lists with delayed elements

Using thread-safe navigable maps

Generating concurrent random numbers

Using atomic variables

Using atomic arrays

Customizing Concurrency Classes


Customizing the ThreadPoolExecutor class

Implementing a priority-based Executor class

Implementing the ThreadFactory interface to generate custom threads

Using our ThreadFactory in an Executor object

Customizing tasks running in a scheduled thread pool

Implementing the ThreadFactory interface to generate custom threads for the Fork/Join framework

Customizing tasks running in the Fork/Join framework

Implementing a custom Lock class

Implementing a transfer Queue based on priorities

Implementing your own atomic object

Testing Concurrent Applications


Monitoring a Lock interface

Monitoring a Phaser class

Monitoring an Executor framework

Monitoring a Fork/Join pool

Writing effective log messages

Analyzing concurrent code with FindBugs

Configuring Eclipse for debugging concurrency code

Configuring NetBeans for debugging concurrency code

Testing concurrency code with MultithreadedTC