The lock in Java can be divided into "synchronous lock" and the lock inside the Juc package (locks package)
Synchronization Lock: That is, through the Synchronized keyword to synchronize, to achieve a mutually exclusive access to competing resources lock. Synchronization locks are already supported in Java version 1.0. The principle of a synchronous lock is that there is only one synchronization lock for each object, and the synchronization lock can be accessed by different threads together. However, at the same point in time, the synchronization lock can and can only be obtained by one thread. In this way, the thread that acquires the synchronization lock is able to perform CPU scheduling, which executes on the CPU, and no thread that acquires the synchronization lock must wait until the synchronization lock is acquired before it can continue to run.
Locks Package: The lock in the JUC package is more powerful than a sync lock, and it provides a framework for locks that allow more flexibility in the use of locks, which is more complex than native synchronization locks.
Java Concurrent Programming Series (iii)-locks lock mechanism class