【锁】synchronized 和ReentrantLock

1. Lock implementation

synchronized is implemented by the JVM, JDK and ReentrantLock is achieved.

2. Performance

The new version of the Java synchronized were a lot of optimization, such as spin locks, etc., synchronized with ReentrantLock roughly the same.

3. Wait interruptible

When the thread holding the lock release locks for long periods, waiting thread can choose to give up waiting, changed other things.

ReentrantLock can be interrupted, but not synchronized.

4. Lock fair

Fair lock means multiple threads at the same time waiting for a lock, the lock must be obtained sequentially in chronological order application lock.

The non-synchronized lock fair, ReentrantLock default is unfair, but it may also be fair.

The plurality of lock condition Binding

Condition a ReentrantLock can bind multiple objects simultaneously.

Guess you like

Origin www.cnblogs.com/itplay/p/11102776.html