Lock Interface In Java

What is Lock Interface? Lock provides the same functionality as a synchronized block. Like synchronized, a lock is a tool for controlling access to a critical region by multiple threads. Example using synchronized block: Example using Lock class: Note: how lock() and unlock() methods are called on Lock object to secure critical region. Why is…