Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected final boolean tryRelease(int releases) {
- int c = getState() - releases; // 从锁状态减去释放的锁量
- if (Thread.currentThread() != getExclusiveOwnerThread())
- throw new IllegalMonitorStateException();
- boolean free = false;
- if (c == 0) { // 状态为0表示锁被完全释放,成为可用状态
- free = true;
- setExclusiveOwnerThread(null); // 重置锁的拥有者线程
- }
- setState(c);
- return free;
- }
Add Comment
Please, Sign In to add comment