File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -267,19 +267,19 @@ ReentrantLock 分为**公平锁**和**非公平锁**,可以通过构造方法
267267 return false ;
268268 }
269269
270- // 尝试释放锁
271- protected final boolean tryRelease(int releases) {
272- int c = getState() - releases;
273- if (Thread . currentThread() != getExclusiveOwnerThread())
274- throw new IllegalMonitorStateException ();
275- boolean free = false ;
276- if (c == 0 ) {
277- free = true ;
278- setExclusiveOwnerThread(null );
279- }
280- setState(c);
281- return free;
282- }
270+ // 尝试释放锁
271+ protected final boolean tryRelease(int releases) {
272+ int c = getState() - releases;
273+ if (Thread . currentThread() != getExclusiveOwnerThread())
274+ throw new IllegalMonitorStateException ();
275+ boolean free = false ;
276+ if (c == 0 ) {
277+ free = true ;
278+ setExclusiveOwnerThread(null );
279+ }
280+ setState(c);
281+ return free;
282+ }
283283```
284284
285285首先会判断当前线程是否为获得锁的线程,由于是重入锁所以需要将 ` state ` 减到 0 才认为完全释放锁。
You can’t perform that action at this time.
0 commit comments