Explicit locks in Java 5 (ctd)

On the previous page, we introduced the notion of a lock, used to manage access to shared data. Java 5 introduces classes that implement explicit locks. Explicit locks are useful in cases where you need to overcome some of the shortcomings of built-in synchronization. In particular, they have the following features:

The package java.util.concurrent.locks contains the various lock classes and interfaces. The most significant of these to most applications are three interfaces: Lock, ReadWriteLock, and Condition, plus the two lock implementations ReentrantLock and ReentrantReadWriteLock. (The package also contains a few other abstract classes that are useful if you are implementing a new lock type; we won't look at those here.)

On the next page, we look at an example of using a Java 5 Lock instance.


If you enjoy this Java programming article, please share with friends and colleagues. Follow the author on Twitter for the latest news and rants.

Editorial page content written by Neil Coffey. Copyright © Javamex UK 2021. All rights reserved.