一、前言
关于javolution源码包javolution.util.ReentrantLock线程同步锁,实现java.util.concurrent.locks.ReentrantLock并发包队列线程锁实现功能,详情参见源码说明。
二、源码说明
package javolution.util;@b@@b@public class ReentrantLock@b@{@b@ private Thread _owner;@b@ private long _count;@b@@b@ public void lock()@b@ {@b@ Thread caller = Thread.currentThread();@b@ synchronized (this) {@b@ if (caller == this._owner)@b@ this._count += 1L;@b@ else@b@ try {@b@ while (this._owner != null)@b@ super.wait();@b@@b@ this._owner = caller;@b@ this._count = 1L;@b@ } catch (InterruptedException exception) {@b@ monitorexit; return;@b@ }@b@ }@b@ }@b@@b@ public boolean tryLock()@b@ {@b@ synchronized (this) {@b@ if (this._owner != null) break label19;@b@ lock();@b@ return true;@b@@b@ label19: return false;@b@ }@b@ }@b@@b@ public void unlock()@b@ {@b@ synchronized (this) {@b@ if (Thread.currentThread() == this._owner)@b@ if (--this._count == 0L) {@b@ this._owner = null;@b@ super.notify();@b@ }@b@ else@b@ throw new IllegalMonitorStateException("Current thread does not hold this lock");@b@ }@b@ }@b@@b@ public Thread getOwner()@b@ {@b@ synchronized (this) {@b@ return this._owner;@b@ }@b@ }@b@}