class X {
private final ReentrantLock lock = new ReentrantLock();
// ...
public void m(){
lock.lock(); // block until condition holds
try {
// ... method body
} finally{
lock.unlock()
}
}
}
JDK并发工具包中,很多异常处理都使用了如下的结构,如AbstractExecutorService,即只有try和finally没有catch。class X { private final ReentrantLock lock = new ReentrantLock(); // ... public void m(){ lock.lock(); // block until c