Skip to content

Latest commit

 

History

History
17 lines (16 loc) · 423 Bytes

lockInterruptibly.md

File metadata and controls

17 lines (16 loc) · 423 Bytes

可中断的锁

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