/**
* Acquires in exclusive mode, ignoring interrupts. Implemented
* by invoking at least once {@link #tryAcquire},
* returning on success. Otherwise the thread is queued, possibly
* repeatedly blocking and unblocking, invoking {@link
* #tryAcquire} until success. This method can be used
* to implement method {@link Lock#lock}.
*
* @param arg the acquire argument. This value is conveyed to
* {@link #tryAcquire} but is otherwise uninterpreted and
* can represent anything you like.
*/
public final void acquire(int arg) {
if (!tryAcquire(arg) &&
acquireQueued(addWaiter(Node.EXCLUSIVE), arg))
selfInterrupt();
}
一、acquire的三个步骤
先看看当前线程能否获得资源,如果能获得资源,就不用调用acquireQueued了。
1.尝试获取——tryAcquire方法
{@link java.util.concurrent.locks.AbstractQueuedSynchronizer#acquire(int)},以排它的方式获得锁,对中断不敏感,完成synchronized语义。
1.尝试获取<br/>
{@l