protectedfinalbooleantryAcquire(int acquires) {finalThread current =Thread.currentThread();int c =getState();if (c ==0) {if (compareAndSetState(0, acquires)) {setExclusiveOwnerThread(current);returntrue; } }elseif (current ==getExclusiveOwnerThread()) {int nextc = c + acquires;if (nextc <0) // overflowthrownewError("Maximum lock count exceeded");setState(nextc);returntrue; }returnfalse; }protectedfinalbooleantryRelease(int releases) {int c =getState()- releases;if (Thread.currentThread() !=getExclusiveOwnerThread())thrownewIllegalMonitorStateException();boolean free =false;if (c ==0) { free =true;setExclusiveOwnerThread(null); }setState(c);return free; }protectedfinalbooleanisHeldExclusively() {// While we must in general read state before owner,// we don't need to do so to check if current thread is ownerreturngetExclusiveOwnerThread()==Thread.currentThread(); }