码迷,mamicode.com
首页 > 其他好文 > 详细

AQS 与 LockSupport

时间:2014-09-27 18:00:40      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   使用   ar   for   

1.结构

bubuko.com,布布扣

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.

AQS 与 LockSupport

标签:style   blog   http   color   io   os   使用   ar   for   

原文地址:http://www.cnblogs.com/yuyutianxia/p/3996479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!