重点:ReentrantLock+Condition,await、signal方法 VS synchronized+Object的wait、notify
1. ReentrantLock对比snchronized
ReentrantLock支持公平锁和非公平锁、可中断。
// 非公平锁(默认)
final ReentrantLock lock = new ReentrantLock();
final ReentrantLock lock = new ReentrantLock(false);
// 公平锁
final ReentrantLock lock = new ReentrantLock(true);
synchronized只支持非公平锁,不可中断。
2. Condition的await,signal对比Object的wait、notify
// Condition
boolean await(long time, TimeUnit unit) throws InterruptedException;
boolean awaitUntil(Date deadline) throws InterruptedException;
// Object
public final native void wait(long timeout) throws InterruptedException;
public final void wait(long timeout, int nanos) throws InterruptedException {
if (timeout < 0) {
throw new IllegalArg