标签:style blog http color io os 使用 ar for
1.结构
Lock的实现类其实都是构建在AbstractQueuedSynchronizer上,每个Lock实现类都持有自己内部类Sync的实例
二。LockSupport
This class associates, with each thread that uses it, a permit (in the sense of the Semaphore
class). A call to park
will return immediately
if the permit is available, consuming it in the process; otherwise it may block. A call to unpark
makes the permit available, if it was not
already available. (Unlike with Semaphores though, permits do not accumulate. There is at most one.)
此类以及每个使用它的线程与一个permit关联(从 Semaphore
类的意义上说)。如果该许可可用,并且可在进程中使用,则调用 park
将立即返回;否则可能 阻塞。
如果许可尚不可用,则可以调用 unpark
使其可用。(与 Semaphore 不同的是,permit不能累积,并且最多只能有一个)
1.park
public static void park()
Disables the current thread for thread scheduling purposes unless the permit is available.
If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread
scheduling purposes and lies dormant until one of three things happens:
1.Some other thread invokes unpark with the current thread as the target
2.Some other thread interrupts the current thread
3.The call spuriously (that is, for no reason) returns
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the thread
to park in the first place. Callers may also determine, for example, the interrupt status of the thread upon return.
标签:style blog http color io os 使用 ar for
原文地址:http://www.cnblogs.com/yuyutianxia/p/3996479.html