Java并发编程学习笔记

可中断的锁

public boolean sendOnSharedLine(Stringmessage)  
      throws InterruptedException{ 
    lock.lockInterruptibly(); //如果当前线程未被中断,则获取锁定。  
    try{ 
        return cancellableSendOnSharedLine(message); 
    }finally{ 
        lock.unlock(); 
    } 
} 
private boolean cancellableSendOnSharedLine(String message) 
    throwsInterruptedException{...} 
}