1. public final void await() throws InterruptedException {
    2. if (Thread.interrupted())
    3. throw new InterruptedException();
    4. Node node = addConditionWaiter();
    5. int savedState = fullyRelease(node);
    6. int interruptMode = 0;
    7. while (!isOnSyncQueue(node)) {
    8. LockSupport.park(this);
    9. if ((interruptMode = checkInterruptWhileWaiting(node)) != 0)
    10. break;
    11. }
    12. if (acquireQueued(node, savedState) && interruptMode != THROW_IE)
    13. interruptMode = REINTERRUPT;
    14. if (node.nextWaiter != null) // clean up if cancelled
    15. unlinkCancelledWaiters();
    16. if (interruptMode != 0)
    17. reportInterruptAfterWait(interruptMode);
    18. }
    1. private Node addConditionWaiter() {
    2. Node t = lastWaiter;
    3. // If lastWaiter is cancelled, clean out.
    4. if (t != null && t.waitStatus != Node.CONDITION) {
    5. unlinkCancelledWaiters();
    6. t = lastWaiter;
    7. }
    8. //Node.CONDITION -2
    9. Node node = new Node(Thread.currentThread(), Node.CONDITION);
    10. if (t == null)
    11. firstWaiter = node;
    12. else
    13. t.nextWaiter = node;
    14. lastWaiter = node;
    15. return node;
    16. }