Java - JSR 166: Concurrency Utilities

[Last Updated: May 21, 2018]

Under JSR-166, Java 1.5 released a scalable, robust, high-performance concurrency utility API, intended to simplify the development of multithreaded applications.

Why JSR-166 was needed?

Using low level facilities like: creating and managing thread objects (java.lang.Thread), using volatile primitives/reference object, using wait/notify and synchronized methods/blocks are not very productive and flexible, and sometimes error-prone. Also using these low level constructs doesn't promote reusability. JSR-166 was introduced to address these problems.

What API it provides?

Following packages provide a powerful, extensible framework of high-level and high-performance threading utilities which help programmer to write robust and scalable thread safe code. It promotes reusability and programmers don't have to reinvent the wheel every time for the common problems.

JVM improvements

In addition to the above API, JSR-166 includes the following JVM improvements

  • Using platform level atomic operation: Compare-and-swap, Load-linked/Store-conditional, Locks instructions.
    Modern processors designed for multiprocessor environments provide hardware primitives to support synchronization (often called "read-modify-write operations"), such as compare-and-swap (CAS), or load-linked/store-conditional (LL/SC).
  • Using platform level built-in locking facilities.
  • Nanosecond-precision timing. All above API that take timeout parameters can specify timeouts in seconds, milliseconds, microseconds, or nanoseconds, through the use of the new TimeUnit enum.

What's next?

In next tutorials, we will go through the main features of this API, except for the concurrent collection which we have already covered in Java Collections Framework(Concurrent collections and Concurrent Maps).

See Also