Lock Interface

The Lock interface explained with examples.

If you are interviewing, consider buying our number#1 course for Java Multithreading Interviews.

Explanation

The Lock interface provides a tool for implementing mutual exclusion that is more flexible and capable than synchronized methods and statements. A single thread is allowed to acquire the lock and gain access to a shared resource, however, some implementing classes such as the ReentrantReadWriteLock allow multiple threads concurrent access to shared resource. The use of synchronized methods or statements ...