Inside AbstractQueuedSynchronizer (3)
Inside AbstractQueuedSynchronizer (1)
Inside AbstractQueuedSynchronizer (2)
Inside AbstractQueuedSynchronizer (3)
Inside AbstractQueuedSynchronizer (4)
?
3.4 Template Method
??? AbstractQueuedSynchronizer提供了以下几个protected方法用于子类改写
int ws = pred.waitStatus; if (ws == Node.SIGNAL)//下次循环判断 返回true block线程 /* * This node has already set status asking a release * to signal it, so it can safely park. */ return true; if (ws > 0) { /* * Predecessor was cancelled. Skip over predecessors and * indicate retry. */ do { node.prev = pred = pred.prev; } while (pred.waitStatus > 0); pred.next = node; } else { /* * waitStatus must be 0 or PROPAGATE. Indicate that we * need a signal, but don't park yet. Caller will need to * retry to make sure it cannot acquire before parking. */ compareAndSetWaitStatus(pred, ws, Node.SIGNAL);//第一次设置,标志需要这样一个信号 } return false;