protectedfinalbooleantryAcquire(int acquires){Thread current =Thread.currentThread();int c =getState();int w =exclusiveCount(c);if(c !=0){//存在读锁或者当前获取线程不是已经获取写锁的线程if(w !=0|| current !=getExclusiveOwnerThread())
retrun false;if(w +exclusiveCount(acquires)> MAX_COUNT)thrownewError("Maximum lock count exceeded");setState(c+acquires);returntrue;}if(writerShouldBlock()||!compareAndSetState(c, c + acquires)){returnfalse;}setExclusiveOwnerThread(current);returntrue;}