Prior to Java 1.5, synchronized and volatile keyword were only way to coordinate access to shared variable, but Java 5 provides another alternative in terms of ReentrantLock. ReentrantLock offers features, which synchronized keyword lacks and which are essential to building non blocking algorithm, such as trying for lock without getting blocked, trying for lock interruptibly and trying lock with timeout. Though ReentrantLock offer same ordering and visibility guarantee, it comes with a danger, programmer need to take care of acquisition and release of lock, which if not difficult but can lead to subtle bugs if programmer forget to release lock in finally block.
java
opinion
how-to
open source