{"id":2398,"date":"2022-07-26T01:18:24","date_gmt":"2022-07-25T17:18:24","guid":{"rendered":"http:\/\/47.101.202.111\/?p=2398"},"modified":"2023-04-03T11:20:21","modified_gmt":"2023-04-03T03:20:21","slug":"locksupport-%e7%ba%bf%e7%a8%8b%e9%98%bb%e5%a1%9e%e5%92%8c%e5%94%a4%e9%86%92%e6%9c%ba%e5%88%b6%e7%bb%86%e8%8a%82","status":"publish","type":"post","link":"http:\/\/139.196.114.170\/?p=2398","title":{"rendered":"LockSupport &#8211; \u7ebf\u7a0b\u963b\u585e\u548c\u5524\u9192\u673a\u5236\u7ec6\u8282"},"content":{"rendered":"<p>LockSupport\u63a5\u53e3\u63d0\u4f9b\u4e86\u7ebf\u7a0b\u963b\u585e\u548c\u5524\u9192\u65b9\u6cd5\uff0c\u5176\u4e2d\u5524\u9192\u673a\u5236\u5728\u5b98\u65b9\u6587\u6863\u4e2d\u63d0\u5230\u4e00\u4e9btricks\uff0c\u672c\u6587\u5bf9\u5176\u52a0\u4ee5\u5b9e\u4f8b\u8ba8\u8bba\u9a8c\u8bc1\u3002\u53e6\u5bf9\u5b98\u65b9\u6848\u4f8b\u6df1\u5165\u5206\u6790\uff0c\u505a\u51fa\u4e00\u4e9b\u601d\u8003\u8ba8\u8bba<\/p>\n<p><!--more--><\/p>\n<h3>\u963b\u585e\u6307\u5b9a\u7ebf\u7a0b park<\/h3>\n<pre lang=\"java\">\npublic static void park(Object blocker)\npublic static void parkNanos(Object blocker, long nanos)\npublic static void parkUntil(Object blocker, long deadline)\n<\/pre>\n<h4>park()<\/h4>\n<p>\u5c06\u5f53\u524d\u7ebf\u7a0b\u963b\u585e\u5728park()\u4ee3\u7801\u884c\uff0c\u4e09\u79cd\u60c5\u51b5\u4f1a\u88ab\u5524\u9192\u7ee7\u7eed\u6267\u884c\uff1a<br \/>\n1\uff09\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528unpark(currentThread)\u5524\u9192\u5f53\u524d\u7ebf\u7a0b<br \/>\n2\uff09\u5f53\u524d\u7ebf\u7a0b\u88ab\u5176\u4ed6\u7ebf\u7a0b <strong>\u6253\u65ad\uff0c\u4f46\u662f\u4ec5\u5524\u9192\u4e0d\u629bInterruptedException<\/strong>\u3002\u53ef\u5728park()\u65b9\u6cd5\u540e\u8fd0\u884cThread.interrupted()\u68c0\u6d4b\u5524\u9192\u662f\u5426\u7531\u4e8e\u4e2d\u65ad\u5f15\u8d77<br \/>\n3\uff09\u6ca1\u6709\u4efb\u4f55\u7406\u7531\u81ea\u5df1\u5524\u9192\uff08\u865a\u5047\u5524\u9192\uff09\u3002<strong>\u4e3a\u907f\u514d\u865a\u5047\u5524\u9192\uff0c\u5e94\u5c06park()\u65b9\u6cd5\u7f6e\u4e8e\u5faa\u73af\u4e2d<\/strong><\/p>\n<h4>park(Object blocker)<\/h4>\n<p>\u5c06\u6b63\u5728\u6267\u884cblocker\u5bf9\u8c61\u4ee3\u7801\u7684\u5f53\u524d\u7ebf\u7a0b\u963b\u585e\u5728park()\u4ee3\u7801\u884c\uff0c\u88ab\u5524\u9192\u7684\u4e09\u79cd\u60c5\u51b5\u540cpark()\uff0c\u7ebf\u7a0bdump\u65f6\u4f1a\u663e\u793a\u963b\u585e\u5bf9\u8c61blocker<\/p>\n<h4>parkNanos(long nanos)<\/h4>\n<p>\u5c06\u5f53\u524d\u7ebf\u7a0b\u963b\u585e\u5728parkNanos\u4ee3\u7801\u884c\u5904\uff0c\u82e5\u7ebf\u7a0b\u963b\u585e\u65f6\u957f\u5728(0,nanos)\u533a\u95f4\u672a\u88ab\u4e0a\u8ff0\u4e09\u79cd\u60c5\u51b5\u5524\u9192\uff0c\u5219\u5728\u963b\u585e\u65f6\u957f\u8fbe\u5230nanos\u65f6\u81ea\u5524\u9192\uff0c\u907f\u514d\u6c38\u4e45\u7b49\u5f85<\/p>\n<h4>parkUntil(long deadline)<\/h4>\n<p>\u5c06\u5f53\u524d\u7ebf\u7a0b\u963b\u585e\u5728parkUntil\u4ee3\u7801\u884c\u5904\uff0c\u82e5\u7ebf\u7a0b\u5728\u7edd\u5bf9\u65f6\u95f4deadline\u524d\u672a\u88ab\u4e0a\u8ff0\u4e09\u79cd\u60c5\u51b5\u5524\u9192\uff0c\u5219\u5728\u7edd\u5bf9\u65f6\u95f4deadline\u540e\u81ea\u5524\u9192\uff0c\u907f\u514d\u6c38\u4e45\u7b49\u5f85<\/p>\n<h3>\u5524\u9192\u6307\u5b9a\u7ebf\u7a0b unpark<\/h3>\n<pre lang=\"java\">\npublic static void unpark(Thread thread)\n<\/pre>\n<p>\u5524\u9192\u963b\u585e\u5728park()\u4ee3\u7801\u884c\u7684\u7ebf\u7a0b\u7ee7\u7eed\u5411\u4e0b\u6267\u884c\uff0c\u6709\u5982\u4e0b\u51e0\u70b9\u7ec6\u8282\u9700\u6ce8\u610f<\/p>\n<h4>\u6bcf\u4e2aunpark()\u5524\u9192\u4e00\u4e2a\u7ebf\u7a0b\u7684park()<\/h4>\n<p>\u4e00\u822cpark()\u5728\u5148\uff0cunpark()\u5728\u540e\uff0c\u6210\u5bf9\u4f7f\u7528<\/p>\n<pre><code class=\"language-java\">public static void main(String[] args) {\n    final Thread t1 = new Thread(() -&gt; {\n        long start, end;\n        System.out.println(&quot;time before park : &quot; + (start = System.currentTimeMillis()));\n        LockSupport.park();\n        System.out.println(&quot;time after park : &quot; + (end = System.currentTimeMillis()));\n        System.out.println(&quot;t1 is unpark by t2, time for waiting : &quot; + (end - start));\n    });\n    t1.start();\n\n    new Thread(() -&gt; {\n        try {\n            Thread.sleep(5000);\n            LockSupport.unpark(t1);\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        }\n    }).start();\n}<\/code><\/pre>\n<pre>\ntime before park : 1664120513742\ntime after park : 1664120518748\nt1 is unpark by t2, time for waiting : 5006\n<\/pre>\n<h4>\u591a\u4f59\u7684unpark()\u4f7f\u6d3b\u8dc3\u7ebf\u7a0b\u7684\u4e0b\u6b21park()\u5931\u6548<\/h4>\n<p>\u6b64\u5904\u5728\u7ebf\u7a0b\u542f\u52a8\u4e4b\u540e\u3001park()\u4e4b\u524d\u6267\u884c\u7684unpark()\uff0c\u4f7f\u5f97\u672c\u6b21park()\u5931\u6548<\/p>\n<pre><code class=\"language-java\">public static void main(String[] args) {\n    System.out.println(Thread.currentThread().getName() + System.currentTimeMillis());\n    Thread t = new Thread(() -&gt; {\n        long start, end;\n        System.out.println(Thread.currentThread().getName() + (start = System.currentTimeMillis()));\n        try {\n            Thread.sleep(5000);\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        }\n        LockSupport.park();\n        System.out.println(Thread.currentThread().getName() + (end = System.currentTimeMillis()));\n        System.out.println(&quot;this park is unabled by last unpark, margin millis is &quot; + (end - start));\n    });\n    t.start();\n    LockSupport.unpark(t);\n    System.out.println(Thread.currentThread().getName() + System.currentTimeMillis());\n}<\/code><\/pre>\n<pre>\nmain1664115567502\nThread-01664115567532\nmain1664115567532\nThread-01664115572542\nthis park is unabled by last unpark, margin millis is 5010\n<\/pre>\n<h4>park\u4e4b\u524d\u7684\u591a\u6b21unpark()\u7b49\u4ef7\u4e8e\u4e00\u6b21unpark()<\/h4>\n<p>\u5982\u4e0b\u4f8b\u4e2dpark()\u4e4b\u524d\u7684\u4e09\u6b21unpark()\u4ec5\u53ef\u6210\u529f\u6d88\u89e3\u4e00\u6b21park()<\/p>\n<pre><code class=\"language-java\">public static void main(String[] args) {\n    Thread t = new Thread(() -&gt; {\n        try {\n            Thread.sleep(5000);\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        }\n        LockSupport.park();\n        System.out.println(&quot;unpark success 1&quot;);\n        LockSupport.park();\n        System.out.println(&quot;unpark success 2&quot;);\n        LockSupport.park();\n        System.out.println(&quot;unpark success 3&quot;);\n    });\n    t.start();\n    LockSupport.unpark(t);\n    LockSupport.unpark(t);\n    LockSupport.unpark(t);\n}<\/code><\/pre>\n<pre>\nunpark success 1\n<\/pre>\n<h4>\u7ebf\u7a0b\u542f\u52a8\u4e4b\u524d\u7684unpark()\u4e0d\u5bf9\u7ebf\u7a0bpark()\u751f\u6548<\/h4>\n<pre><code class=\"language-java\">public static void main(String[] args) {\n    Thread t = new Thread(() -&gt; {\n        LockSupport.park();\n        System.out.println(&quot;unpark before thread start works&quot;);\n    });\n    LockSupport.unpark(t);\n    t.start();\n}<\/code><\/pre>\n<p>\u7ebf\u7a0b\u88ab\u963b\u585e\u672a\u8f93\u51fa\u4efb\u4f55\u7ed3\u679c<\/p>\n<pre>\n<\/pre>\n<h3>\u5b98\u65b9\u5b9e\u4f8b\u89e3\u6790<\/h3>\n<p>FIFOMutex\u662f\u516c\u5e73\u9501\uff1a\u7ebf\u7a0b\u5165\u961f\u6210\u4e3a\u961f\u5217\u8282\u70b9\uff0c\u53ea\u5141\u8bb8\u961f\u5934\u7ebf\u7a0b\u83b7\u53d6\u9501\uff0c\u56e0\u800c\u4fdd\u8bc1\u4e86\u6309\u6392\u961f\u987a\u5e8f\u83b7\u53d6\u9501<\/p>\n<h4>\u4ee3\u7801\u8be6\u7ec6\u5206\u6790<\/h4>\n<p>\u672c\u9501\u662fAQS\u4e2dReetrantLock\u516c\u5e73\u9501\u7684\u7b80\u5316\u7248\u5b9e\u73b0\uff0c\u539f\u7406\u56fe\u7c7b\u4f3c\uff0c\u53ef\u53c2\u8003\u76f8\u5173\u6587\u7ae0<\/p>\n<pre><code class=\"language-java\">class FIFOMutex {\n    \/\/ locked\u72b6\u6001\uff1afalse\u4e3a\u9501\u7a7a\u95f2\uff0ctrue\u4e3a\u9501\u5360\u6709\n    private final AtomicBoolean locked = new AtomicBoolean(false);\n    \/\/ \u5e76\u53d1\u5b89\u5168\u7684\u961f\u5217\n    private final Queue&lt;Thread&gt; waiters = new ConcurrentLinkedQueue&lt;Thread&gt;();\n\n    public void lock() {\n        boolean wasInterrupted = false;\n        Thread current = Thread.currentThread();\n        \/\/ \u5f53\u524d\u7ebf\u7a0b\u8fdb\u961f\u5217\n        waiters.add(current);\n\n        \/\/ 1. \u5f53\u524d\u7ebf\u7a0b\u4e0d\u662f\u961f\u9996\uff0c\u76f4\u63a5\u6302\u8d77\n        \/\/ 2. \u5f53\u524d\u961f\u9996\u7ebf\u7a0b\u7531\u4e8e\u4e0a\u4e2a\u961f\u9996\u7ebf\u7a0b\u5360\u6709\u9501\uff0cCAS\u7ade\u4e89\u9501\u5931\u8d25\u6302\u8d77\n        while (waiters.peek() != current ||\n               !locked.compareAndSet(false, true)) {\n            LockSupport.park(this);\n            \/\/ \u7ebf\u7a0b\u6062\u590d\u8fd0\u884c\u540e\u5224\u65ad\u662f\u5426\u662f\u7531\u4e8e\u88ab\u6253\u65ad\u800c\u5524\u9192\n            if (Thread.interrupted())\n                wasInterrupted = true;\n        }\n\n        \/\/ \u5f53\u524d\u7ebf\u7a0b\u662f\u961f\u9996\u4e14CAS\u7ade\u4e89\u9501\u6210\u529f\u51fa\u961f\u5217\u653e\u884c\uff0c\u6267\u884c\u5b8clock()\u65b9\u6cd5\u540e\u8fdb\u5165\u9501\u533a\n        waiters.remove();\n        \/\/ \u6062\u590d\u7ebf\u7a0b\u6253\u65ad\u5904\u7406\n        if (wasInterrupted)\n            current.interrupt();\n    }\n\n    public void unlock() {\n        \/\/ \u6267\u884c\u6b64\u65b9\u6cd5\u7684\u7ebf\u7a0b\u5fc5\u662f\u81ea\u65cb\u7ade\u4e89\u9501\u6210\u529f\u7684\u7ebf\u7a0b\uff0c\u5176\u4ed6\u7ebf\u7a0b\u5747\u5728lock\u9636\u6bb5park\u963b\u585e\n        locked.set(false);\n        \/\/ \u5524\u9192\u961f\u5934\u7ebf\u7a0b\n        LockSupport.unpark(waiters.peek());\n    }\n}<\/code><\/pre>\n<h4>\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u5e76\u53d1\u5b89\u5168\u7684\u961f\u5217<\/h4>\n<p>\u624b\u5199\u4e2a\u7b80\u5355\u961f\u5217\uff0c\u4ee5\u5165\u961f\u64cd\u4f5c\u4e3a\u4f8b\u8bf4\u660e\u5e76\u53d1\u4e0d\u5b89\u5168\u7684\u540e\u679c<\/p>\n<pre><code class=\"language-java\">public class SimpleQueue {\n    Node head = new Node(-1);\n    Node tail = head;\n\n    static class Node {\n        Node next;\n        int name;\n\n        public Node(int name) {\n            this.name = name;\n            this.next = null;\n        }\n\n    }\n\n    public void add(int e) {\n        Node node = new Node(e);\n        tail.next = node;\n        tail = tail.next;\n    }\n\n    public void print() {\n        Node cur = head;\n        while (cur != null) {\n            System.out.println(cur.name + &quot; &quot;);\n            cur = cur.next;\n        }\n    }\n\n    public static void main(String[] args) throws InterruptedException, IOException {\n        SimpleQueue q = new SimpleQueue();\n        Thread t1 = new Thread(() -&gt; {\n            for (int i = 0; i &lt; 100000; i += 2) {\n                q.add(i);\n            }\n        });\n        Thread t2 = new Thread(() -&gt; {\n            for (int i = 1; i &lt; 100000; i += 2) {\n                q.add(i);\n            }\n        });\n        t1.start(); t2.start();\n        \/\/ main\u7ebf\u7a0b\u7b49\u5f85t1\u3001t2\u6267\u884c\u5b8c\u6bd5\u540e\u518d\u6267\u884c\u8f93\u51fa\n        t2.join(); t1.join();\n        q.print();\n    }\n}<\/code><\/pre>\n<p>javap -c(\u53cd\u7f16\u8bd1class) -l(\u884c\u53f7\u548c\u672c\u5730\u53d8\u91cf\u8868) -v(\u9644\u52a0\u4fe1\u606f) \u5f97\u5230\u4e0a\u8ff0\u4ee3\u7801\u7684\u7f16\u8bd1\u5b57\u8282\u7801\uff0c\u8fc7\u6ee4\u51faadd()\u76f8\u5173\u5185\u5bb9<\/p>\n<pre lang=\"java\">\nConstant pool:\n    #2 = Class              #74         \/\/ copy\/SimpleQueue$Node\n    #3 = Methodref          #2.#75      \/\/ copy\/SimpleQueue$Node.\"<init>\":(I)V\n    #5 = Fieldref           #16.#77     \/\/ copy\/SimpleQueue.tail:Lcopy\/SimpleQueue$Node;\n    #6 = Fieldref           #2.#78      \/\/ copy\/SimpleQueue$Node.next:Lcopy\/SimpleQueue$Node;\n\n  public void add(int);\n    descriptor: (I)V\n    flags: ACC_PUBLIC\n    Code:\n      stack=3, locals=3, args_size=2\n         0: new           #2            \/\/ class copy\/SimpleQueue$Node \u521b\u5efaSimpleQueue.Node\u5b9e\u4f8b\n         3: dup                         \/\/ \u590d\u5236\u6808\u9876\u5f15\u7528\u538b\u5165\u64cd\u4f5c\u6570\u6808\n         4: iload_1                     \/\/ \u5c06\u5c40\u90e8\u53d8\u91cfint e\u538b\u5165\u64cd\u4f5c\u6570\u6808\n         5: invokespecial #3            \/\/ Method copy\/SimpleQueue$Node.\"<init>\":(I)V SimpleQueue.Node\u6784\u9020\u65b9\u6cd5\n         8: astore_2                    \/\/ \u5c06\u5f15\u7528node\u4ece\u64cd\u4f5c\u6570\u6808\u9876\u51fa\u6808\uff0c\u5b58\u5230\u5c40\u90e8\u53d8\u91cf\u8868\uff0c\u5bf9\u5e94Node node = new Node(e)\u7684\u5f15\u7528\u8d4b\u503c\n         9: aload_0                     \/\/ \u5c06\u5f15\u7528\u7c7b\u578bthis\u8bfb\u5165\u64cd\u4f5c\u6570\u6808\n        10: getfield      #5            \/\/ Field tail:Lcopy\/SimpleQueue$Node; \u83b7\u53d6\u5bf9\u8c61\u6210\u5458\u5f15\u7528\u5b9e\u4f8bthis.tail\u5165\u64cd\u4f5c\u6570\u6808\n        13: aload_2                     \/\/ \u5c06\u5f15\u7528\u7c7b\u578b\u5c40\u90e8\u53d8\u91cfnode\u8bfb\u5165\u64cd\u4f5c\u6570\u6808\n        14: putfield      #6            \/\/ Field copy\/SimpleQueue$Node.next:Lcopy\/SimpleQueue$Node;\u8bbe\u7f6e\u5bf9\u8c61\u6210\u5458\u5f15\u7528\u7c7b\u578btail.next\u4e3a\u64cd\u4f5c\u6570\u6808\u9876\u6570\u636enode\n        17: aload_0                     \/\/ \u5c06\u5f15\u7528\u7c7b\u578bthis\u8bfb\u5165\u64cd\u4f5c\u6570\u6808\n        18: aload_0                     \/\/ \u5c06\u5f15\u7528\u7c7b\u578bthis\u8bfb\u5165\u64cd\u4f5c\u6570\u6808\n        19: getfield      #5            \/\/ Field tail:Lcopy\/SimpleQueue$Node; \u8bfb\u53d6this.tail\u5165\u64cd\u4f5c\u6570\u6808\n        22: getfield      #6            \/\/ Field copy\/SimpleQueue$Node.next:Lcopy\/SimpleQueue$Node; \u8bfb\u53d6this.tail.next\u5165\u64cd\u4f5c\u6570\u6808\n        25: putfield      #5            \/\/ Field tail:Lcopy\/SimpleQueue$Node; \u8bbe\u7f6ethis.tail\u4e3a\u64cd\u4f5c\u6570\u6808\u9876\u6570\u636ethis.tail.next\n        28: return\n      LineNumberTable:\n        line 27: 0\n        line 28: 9\n        line 29: 17\n        line 30: 28\n      LocalVariableTable:\n        Start  Length  Slot  Name   Signature\n            0      29     0  this   Lcopy\/SimpleQueue;\n            0      29     1     e   I\n            9      20     2  node   Lcopy\/SimpleQueue$Node;\n<\/pre>\n<p>\u89c2\u5bdf\u4e0a\u8ff0\u5b57\u8282\u7801\uff0c\u5bf9\u5171\u4eab\u53d8\u91cftail\u7684 \u8bfb-\u6539-\u5199 \u4e0d\u662f\u539f\u5b50\u7684\uff0c\u591a\u4e2a\u7ebf\u7a0b\u6dfb\u52a0\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u6267\u884c\u5230\u7684\u5b57\u8282\u7801\u884c\u53f7\u662f\u4e0d\u540c\u7684\uff0c\u8fd9\u5c31\u53ef\u80fd\u5bfc\u81f4\u4e22\u5931\u4fee\u6539\uff0c\u8fdb\u800c\u5bfc\u81f4\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5982\u4e0b\u56fe\u5206\u6790\uff08\u56fe\u4e2d\u5806\u5185\u5b58\u662f\u5171\u4eab\u5185\u5b58\uff0c\u7ebf\u7a0b\u79c1\u6709\u5185\u5b58\u533a\u57df\u662f\u5355\u6838\u591a\u7ea7\u9ad8\u901f\u7f13\u5b58\uff0c\u7ebf\u7a0b\u79c1\u6709\u7684\u5c40\u90e8\u53d8\u91cf\u8868\u5b58\u50a8\u7684\u662f\u5806\u5185\u5b58\u5bf9\u8c61\u7684\u5f15\u7528\u5730\u5740\u3001\u57fa\u672c\u7c7b\u578b\u6570\u503c\u3002\u6b64\u5904\u65e0\u9700\u8003\u8651\u53ef\u89c1\u6027\u95ee\u9898\uff1agetfield\u6307\u4ee4\u8bfb\u53d6\u5806\u5185\u5b58\u5230\u79c1\u6709\u5185\u5b58\uff0cputfield\u6307\u4ee4\u5c06\u79c1\u6709\u5185\u5b58\u76f4\u63a5\u5199\u5165\u5171\u4eab\u5185\u5b58\uff0c\u65e0\u7f13\u5b58\u4e0d\u4e00\u81f4\u73b0\u8c61\uff09<br \/>\n<img decoding=\"async\" src=\"https:\/\/i0.wp.com\/tihar-tech.cn\/wp-content\/uploads\/2022\/07\/FIFOMutex.png?w=1024\" alt=\"lose update\" \/><\/p>\n<h4>\u5e76\u53d1\u5b89\u5168\u7684FIFO\u4e3a\u4ec0\u4e48\u8fd8\u8981CAS<\/h4>\n<p>\u6211\u4eec\u7684\u771f\u5b9e\u76ee\u7684\u662f\u5b9e\u73b0\u5e76\u53d1\u63a7\u5236\uff0c\u5373 <strong>\u83b7\u5f97\u9501\u7684\u7ebf\u7a0b\u8fdb\u5165\u4e34\u754c\u533a\u4ee3\u7801\uff0c\u7ade\u4e89\u9501\u5931\u8d25\u7684\u7ebf\u7a0b\u8981\u963b\u585e\u7981\u6b62\u8fdb\u5165<\/strong>\uff0c\u6240\u4ee5\u9700\u8981\u7ebf\u7a0bCAS\u83b7\u53d6\u9501\u6765\u51b3\u5b9a\u662f\u5426\u653e\u884c<\/p>\n<p>\u800c\u6211\u4eec\u53ea\u662f\u60f3\u7528FIFO\u961f\u5217\u6765\u63a7\u5236\u7ebf\u7a0b\u4f7f\u7528\u4e34\u754c\u533a\u4ee3\u7801\u7684\u987a\u5e8f\uff0c\u5e76\u53d1\u5b89\u5168\u662f\u9488\u5bf9\u961f\u5217\u5165\u961f\u51fa\u961f\u64cd\u4f5c\u7684\u5e76\u53d1\u5b89\u5168\u800c\u8a00<\/p>\n<p>\u5982\u679c\u4e0d\u52a0CAS\u9650\u5236\uff0c\u6bcf\u4e2a\u961f\u9996\u7ebf\u7a0b\u90fd\u5c06\u6267\u884c\u5b8clock()\u4ee3\u7801\u8fdb\u5165\u4e34\u754c\u533a\uff0c\u5931\u53bb\u4e86\u9501\u7684\u4f5c\u7528<\/p>\n<h4>\u4e3a\u4ec0\u4e48\u8981park()<\/h4>\n<p>\u63a7\u5236\u7ebf\u7a0b\u6682\u505c\uff0c\u9650\u5236\u540c\u65f6\u81ea\u65cb\u7684\u7ebf\u7a0b\u4e2a\u6570\uff1a\u5982\u679c\u975e\u961f\u9996\u7ebf\u7a0b\u4e0dpark()\u963b\u585e\uff0c\u6240\u6709\u975e\u961f\u9996\u8282\u70b9\u5c31\u4f1a\u4e00\u76f4\u81ea\u65cb\u83b7\u53d6\u9501\u9020\u6210CPU\u7a7a\u8f6c\uff0c\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u6027\u80fd\u5f00\u9500<\/p>\n<h3>\u53c2\u8003\u6587\u732e<\/h3>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/index.html\">LockSupport &#8211; Java\u2122 Platform Standard Ed. 8<\/a><br \/>\n\u7fdf\u9646\u7eed, \u859b\u5bbe\u7530. Java\u5e76\u53d1\u7f16\u7a0b\u4e4b\u7f8e[M]. 1. \u7535\u5b50\u5de5\u4e1a\u51fa\u7248\u793e, 2018.<br \/>\n\u65b9\u817e\u98de, \u9b4f\u9e4f, \u7a0b\u6653\u660e. Java\u5e76\u53d1\u7f16\u7a0b\u7684\u827a\u672f[M]. 1. \u673a\u68b0\u5de5\u4e1a\u51fa\u7248\u793e, 2015.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LockSupport\u63a5\u53e3\u63d0\u4f9b\u4e86\u7ebf\u7a0b\u963b\u585e\u548c\u5524\u9192\u65b9\u6cd5\uff0c\u5176\u4e2d\u5524\u9192\u673a\u5236\u5728\u5b98\u65b9\u6587\u6863\u4e2d\u63d0\u5230\u4e00\u4e9btricks\uff0c\u672c\u6587\u5bf9\u5176\u52a0\u4ee5 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/139.196.114.170\/?p=2398\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cLockSupport &#8211; \u7ebf\u7a0b\u963b\u585e\u548c\u5524\u9192\u673a\u5236\u7ec6\u8282\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[69],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2398"}],"collection":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2398"}],"version-history":[{"count":16,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2398\/revisions"}],"predecessor-version":[{"id":2716,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/2398\/revisions\/2716"}],"wp:attachment":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}