美文网首页
LockSupport

LockSupport

作者: IAmWhoAmI | 来源:发表于2018-04-27 20:27 被阅读2次
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 Thread#interrupt 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.
    
    public static void park(Object blocker) {
        Thread t = Thread.currentThread();
        setBlocker(t, blocker);
        UNSAFE.park(false, 0L);
        setBlocker(t, null);
    }

这里setBlocker是为了查问题的时候可以知道在哪里阻塞的作用。

image.png

聊起了hotspot如何实现park和unpark,这里有一点可以知道park 和unpark 通过 set volatile int _counter =0 或 =1 进行通信:
https://blog.csdn.net/hengyunabc/article/details/28126139
https://blog.csdn.net/hengyunabc/article/details/27969613

locksupport Api 文档
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/LockSupport.html

相关文章

  • 并发编程-(3)-LockSupport

    目录: 1、LockSupport工具定位: 2、LockSupport工具定义: 3、LockSupport常用...

  • 并发编程系列之掌握LockSupport的用法

    并发编程系列之掌握LockSupport的用法 1、什么是LockSupport? LockSupport是用于创...

  • Java CAS

    CAS和LockSupport可以说贯穿了java并发包(自旋锁 + CAS + LockSupport + 内存...

  • 5.LockSupport核心原理分析

    LockSupport核心原理分析 在前面分析AQS的时候,经常出现LockSupport.park(this);...

  • Java并发系列 — LockSupport

    本文由【JDK1.8】JUC——LockSupport和【细谈Java并发】谈谈LockSupport这两篇文章整...

  • LockSupport

    总结一下,LockSupport比Object的wait/notify有两大优势: ①LockSupport不需要...

  • LockSupport

    示例用法: LockSupport.park() 对应一个LockSupport.unpark(),类似于一个计...

  • java并发编程之LockSupport

    LockSupport,构建同步组件的基础工具,帮AQS完成相应线程的阻塞或者唤醒的工作。 LockSupport...

  • LockSupport

    LockSupport的park和unpark的基本使用,以及对线程中断的响应性ps: LockSupport.p...

  • 并发:LockSupport

    LockSupport LockSupport看名字叫锁支持,这个玩意的功能跟wait和notify很像,它也是可...

网友评论

      本文标题:LockSupport

      本文链接:https://www.haomeiwen.com/subject/iysrlftx.html