Guest User

Untitled

a guest
Dec 11th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. protected final boolean tryRelease(int releases) {
  2. int c = getState() - releases; // 从锁状态减去释放的锁量
  3. if (Thread.currentThread() != getExclusiveOwnerThread())
  4. throw new IllegalMonitorStateException();
  5. boolean free = false;
  6. if (c == 0) { // 状态为0表示锁被完全释放,成为可用状态
  7. free = true;
  8. setExclusiveOwnerThread(null); // 重置锁的拥有者线程
  9. }
  10. setState(c);
  11. return free;
  12. }
Add Comment
Please, Sign In to add comment