{"id":701,"date":"2014-01-08T11:21:30","date_gmt":"2014-01-08T03:21:30","guid":{"rendered":"http:\/\/coderbee.net\/?p=701"},"modified":"2014-01-08T11:21:30","modified_gmt":"2014-01-08T03:21:30","slug":"juc-concurrentlinkedqueue","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/concurrent\/20140108\/701","title":{"rendered":"JUC ConcurrentLinkedQueue"},"content":{"rendered":"<p><code>java.util.concurrent.ConcurrentLinkedQueue<\/code> \u662f\u4e00\u4e2a\u57fa\u4e8e\u94fe\u63a5\u7ed3\u70b9\u7684\u3001\u65e0\u754c\u3001\u7ebf\u7a0b\u5b89\u5168\u7684\u3001FIFO\u961f\u5217\u3002\u5b83\u7684\u662f\u5b9e\u73b0\u91c7\u7528\u4e86\u65e0\u7b49\u5f85\uff08wait-free\uff09\u3001\u65e0\u9501\uff08lock-free\uff09\u7b97\u6cd5\uff0c\u8be5\u7b97\u6cd5\u57fa\u4e8e Maged M. Michael \u548c Michael L. Scott \u5408\u8457\u7684 <a href=\"http:\/\/www.cs.rochester.edu\/u\/michael\/PODC96.html\">Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms<\/a> \u4e2d\u63cf\u8ff0\u7684\u7b97\u6cd5\u3002<\/p>\n<h3>\u4e00\u3001\u8bbe\u8ba1\u601d\u8def<\/h3>\n<ol>\n<li>\u4f7f\u7528 CAS \u539f\u5b50\u6307\u4ee4\u6765\u5904\u7406\u5bf9\u6570\u636e\u7684\u5e76\u53d1\u8bbf\u95ee\uff0c\u628a\u540c\u6b65\u6700\u5c0f\u5316\u5230\u5355\u4e2a\u786c\u4ef6\u6307\u4ee4\u4e0a\uff1b\u8fd9\u662f\u65e0\u9501\u7b97\u6cd5\u7684\u57fa\u7840\u3002<\/li>\n<li>\u5206\u522b\u7528 head\u3001tail \u4e24\u4e2a\u539f\u5b50\u6307\u9488\u6765\u6307\u5411\u961f\u5934\u548c\u961f\u5c3e\uff0c\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\uff0c\u4f46\u5141\u8bb8 head\u3001tail \u5e76\u4e0d\u603b\u662f\u6307\u5411\u6709\u6548\u7684\u5934\u548c\u5c3e\uff1b\u628a\u5165\u961f\u3001\u51fa\u961f\u9700\u8981\u540c\u6b65\u66f4\u65b0\u7684\u8303\u56f4\u6700\u5c0f\u5316\u5230\u5355\u4e2a\u539f\u5b50\u53d8\u91cf\u4e0a\uff0c\u8fd9\u662f\u65e0\u9501\u7b97\u6cd5\u5b9e\u73b0\u7684\u5173\u952e\u3002<\/li>\n<li>\u5728\u5165\u961f\u3001\u51fa\u961f\u64cd\u4f5c\u4e0a\u5e76\u4e0d\u603b\u662f\u66f4\u65b0 head\u3001tail\uff0c\u800c\u662f\u5728\u591a\u6b21\u64cd\u4f5c\u540e\u624d\u8fdb\u884c\u66f4\u65b0\uff0c\u8282\u7701\u4e86CAS\u6307\u4ee4\u3002\u5177\u6709\u6279\u91cf\u66f4\u65b0\u7684\u6548\u679c\u3002<\/li>\n<li>\u7531\u4e8e head\u3001tail \u5e76\u4e0d\u603b\u662f\u6307\u5411\u5934\u548c\u5c3e\uff0c\u8fd9\u5c31\u662f\u8bf4\uff0c\u961f\u5217\u4f1a\u51fa\u73b0\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u5728 head\u3001tail \u4e0a\u5b9a\u4e49\u4e86\u4e00\u4e9b\u4e0d\u53d8\u5f0f\u6765\u7ef4\u62a4\u7b97\u6cd5\u7684\u6b63\u786e\u6027\u3002<\/li>\n<\/ol>\n<h3>\u4e8c\u3001\u4e0d\u53d8\u5f0f<\/h3>\n<p>\u4e0d\u53d8\u5f0f\u662f\u5728\u6267\u884c\u65b9\u6cd5\u4e4b\u524d\u548c\u4e4b\u540e\uff0c\u961f\u5217\u5fc5\u987b\u8981\u4fdd\u6301\u7684\u3002\u53ef\u53d8\u5f0f\u662f\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u961f\u5217\u5141\u8bb8\u51fa\u73b0\u7684\u4e0d\u4e00\u81f4\u60c5\u51b5\u3002<\/p>\n<h4>head \u7684\u7ea6\u675f<\/h4>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u7ed3\u70b9\u80fd\u591f\u5728 O(1) \u65f6\u95f4\u5230\u8fbe\u7b2c\u4e00\u4e2a\u5b58\u6d3b\uff08\u975e\u5df2\u5220\u9664\uff09\u7ed3\u70b9\uff0c\u5982\u679c\u6709\u7684\u8bdd\u3002<\/p>\n<h5>\u4e0d\u53d8\u5f0f<\/h5>\n<ul>\n<li>\u6240\u6709\u5b58\u6d3b\u7ed3\u70b9\u53ef\u4ee5 \u4ece head \u5f00\u59cb\u901a\u8fc7 succ() \u8bbf\u95ee\u3002<\/li>\n<li><code>head != null<\/code>\u3002<\/li>\n<li><code>(tmp = head).next != tmp || tmp != head<\/code>\uff0c\u8fd9\u4e2a\u4e0d\u53d8\u5f0f\u662f\u8bf4 head \u5728\u65b9\u6cd5\u5f00\u59cb\u4e4b\u524d\u3001\u4e4b\u540e\uff0chead \u6307\u5411\u7684\u7ed3\u70b9\u5e94\u8be5\u662f\u5728\u961f\u5217\u4e0a\u7684\u3002<\/li>\n<\/ul>\n<h5>\u53ef\u53d8\u5f0f<\/h5>\n<ul>\n<li><code>head.item<\/code> \u53ef\u80fd\u662f\u3001\u4e5f\u53ef\u80fd\u4e0d\u662f \u7a7a\u7684\u3002<\/li>\n<li>\u5141\u8bb8 tail \u843d\u540e\u4e8e head\uff0c\u90a3\u662f\u56e0\u4e3a tail \u4e0d\u80fd\u4ece head \u5230\u8fbe\u3002<\/li>\n<\/ul>\n<h4>tail \u7684\u7ea6\u675f<\/h4>\n<p>\u4ece\u5b83\u53ef\u4ee5\u5728 O(1) \u65f6\u95f4\u8bbf\u95ee\u5230\u961f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u7ed3\u70b9\uff08\u552f\u4e00\u7684\u6ee1\u8db3 <code>node.next == null<\/code> \u7684\u7ed3\u70b9\uff09\u3002\u8fd9\u4e2a\u4e5f\u5c31\u662f\u8bf4 tail \u6307\u5411\u7684\u5e76\u4e0d\u603b\u662f\u6700\u540e\u4e00\u4e2a\u5b58\u6d3b\u7ed3\u70b9\u3002<\/p>\n<h5>\u4e0d\u53d8\u5f0f<\/h5>\n<ul>\n<li>\u6700\u540e\u7684\u7ed3\u70b9\u603b\u662f\u53ef\u4ee5\u4ece tail \u5f00\u59cb\u901a\u8fc7 <code>succ()<\/code> \u8bbf\u95ee\u3002<\/li>\n<li><code>tail != null<\/code>\u3002<\/li>\n<\/ul>\n<h5>\u53ef\u53d8\u5f0f<\/h5>\n<ul>\n<li>tail.item \u53ef\u80fd\u662f\u3001\u4e5f\u53ef\u80fd\u4e0d\u662f\u7a7a\u3002<\/li>\n<li>\u5141\u8bb8 tail \u843d\u540e\u4e8e head\uff0c\u90a3\u662f\u56e0\u4e3a tail \u4e0d\u80fd\u4ece head \u5230\u8fbe\u3002<\/li>\n<li>tail.next \u53ef\u80fd\u662f\u3001\u4e5f\u53ef\u80fd\u4e0d\u662f \u81ea\u6307\u5411\u5230 tail\u3002<br \/>\n<!--more--><\/li>\n<\/ul>\n<h3>\u4e09\u3001\u5177\u4f53\u5b9e\u73b0<\/h3>\n<h4>\u5c5e\u6027\u4e0e\u94fe\u8868\u7ed3\u70b9\u7c7b<\/h4>\n<pre><code class=\"java\">\/\/ \u5185\u90e8\u7ed3\u70b9\u7c7b\n\/\/ \u4f5c\u4e3a\u65e0\u9501\u7b97\u6cd5\uff0c\u53ea\u80fd\u901a\u8fc7 volatile \u548c sun.misc.Unsafe UNSAFE \u63d0\u4f9b\u7684\n\/\/  CAS \u64cd\u4f5c\u6765\u4fdd\u8bc1\u5185\u5b58\u53ef\u89c1\u6027\u548c\u539f\u5b50\u6027\u3002\nprivate static class Node&lt;E&gt; {\n    volatile E item; \/\/ \u7ed3\u70b9\u5b58\u50a8\u7684\u5b9e\u9645\u5143\u7d20\n    volatile Node&lt;E&gt; next; \/\/ \u6307\u5411\u540e\u7ee7\u7684\u6307\u9488\n\n    Node(E item) {\n      \/\/ \u4f7f\u7528\u5bbd\u677e\u7684\u5199\u662f\u56e0\u4e3aitem\u53ea\u80fd\u5728\u901a\u8fc7casNext\u53d1\u5e03\u4e4b\u540e\u624d\u80fd\u770b\u5230\u3002\n      \/\/ \uff08\u8fd9\u91cc\u4e5f\u5c31\u662f\u8bf4 UNSAFE.putObject \u7684\u5185\u5b58\u8bed\u4e49\u6bd4 volatile \u5199\u8981\u5bbd\u677e\u4e9b\uff0c\u4e5f\u5c31\u9ad8\u6548\u70b9\uff09\n        UNSAFE.putObject( this, itemOffset, item);\n    }\n\n     boolean casItem(E cmp, E val) {\n         return UNSAFE.compareAndSwapObject( this, itemOffset, cmp, val);\n     }\n\n     void lazySetNext(Node&lt;E&gt; val) {\n         UNSAFE.putOrderedObject( this, nextOffset, val);\n     }\n\n     boolean casNext(Node&lt;E&gt; cmp, Node&lt;E&gt; val) {\n         return UNSAFE.compareAndSwapObject( this, nextOffset, cmp, val);\n     }\n\n     \/\/ \u5176\u4ed6\u65b9\u6cd5\u53ca\u4e00\u4e9b\u5c5e\u6027\u7701\u7565\n}\n\n\/\/ ConcurrentLinkedQueue \u7684\u5c5e\u6027\n\n\/* \u89c1\u4e0a\u9762\u8bf4\u660e *\/\nprivate transient volatile Node&lt;E&gt; head;\n\n\/* \u89c1\u4e0a\u9762\u8bf4\u660e *\/\nprivate transient volatile Node&lt;E&gt; tail;\n<\/code><\/pre>\n<h4>offer \u64cd\u4f5c<\/h4>\n<pre><code class=\"java\">public boolean offer(E e) {\n    checkNotNull(e);\n    final Node&lt;E&gt; newNode = new Node&lt;E&gt;(e);\n\n    for (Node&lt;E&gt; t = tail, p = t;;) {\n        Node&lt;E&gt; q = p.next;\n        if (q == null) {\n             \/\/ p \u662f\u961f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u7ed3\u70b9\u3002\uff08\u540e\u7ee7\u4e3a\u7a7a\u7684\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u5b58\u6d3b\u7ed3\u70b9\u3002\u8fd9\u5f88\u91cd\u8981\uff01\uff09\n            if (p.casNext(null, newNode)) {\n                   \/\/ CAS \u6210\u529f\u4f7f e \u6210\u4e3a\u961f\u5217\u7684\u5143\u7d20\uff0c\u65b0\u8282\u70b9\u53d8\u4e3a \"\u5b58\u6d3b\"\u3002\n\n                   \/\/ \u6bcf\u6b21\u8df3\u8fc7\u4e24\u4e2a\u7ed3\u70b9\uff0c\u4e5f\u5c31\u662f\u4e0d\u662f\u6bcf\u6b21\u6dfb\u52a0\u4e00\u4e2a\u7ed3\u70b9\u90fd\u4fee\u6539tail\u5c5e\u6027\u7684\u3002\n                   \/\/ \u8fd9\u662f\u56e0\u4e3a\u5728\u4e0b\u9762\u7684casTail\u6210\u529f\u4e4b\u524d\uff0c\u5176\u4ed6\u7ebf\u7a0b\u53ef\u80fd\u53c8\u6dfb\u52a0\u4e86\u65b0\u7684\u7ed3\u70b9\uff0c\n                   \/\/ \u6240\u4ee5\u5728\u5e76\u53d1\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2acasTail\u51e0\u4e4e\u603b\u662f\u5931\u8d25\u7684\uff0c\u6ca1\u5fc5\u8981\u6bcf\u6b21\u90fd\u8c03\u7528\u3002\n                   \/\/ \uff08\u8fd9\u91cc\u4e5f\u5c31\u662f\u8bf4 tail \u662f\u6279\u91cf\u66f4\u65b0\u7684\uff09\n                if (p != t) \/\/ hop two nodes at a time\n                   \/\/ \u5931\u8d25\u662f OK\u7684\uff0c\u56e0\u4e3a\u5141\u8bb8tail\u4e0d\u603b\u662f\u6307\u5411\u6700\u540e\u4e00\u4e2a\u7ed3\u70b9\u3002\n                    casTail(t, newNode);\n                return true ;\n            }\n            \/\/ \u4e0e\u5176\u4ed6\u7ebf\u7a0b\u7ade\u4e89 CAS \u5931\u8d25\uff0c\u91cd\u65b0\u8bfb\u53d6 next \u5c5e\u6027\u3002\n        }\n        else if (p == q)\n             \/\/ p == q \u8868\u793a\u7ed3\u70b9 p \u5df2\u7ecf\u4ece\u961f\u5217\u91cc\u79fb\u9664\u3002\u5982\u679c tail \u6ca1\u6709\u88ab\u4fee\u6539\uff0c\u5b83\u4e5f\u88ab\u4ece\u961f\u5217\u79fb\u9664\uff0c\n             \/\/ \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u8df3\u5230 head\uff1b\u5982\u679c tail \u88ab\u4fee\u6539\uff0c\u65b0\u7684tail\u662f\u4e2a\u66f4\u597d\u7684\u8d4c\u6ce8\u3002\n             \/\/ \uff08tail\u4e0d\u662f\u5b9e\u65f6\u66f4\u65b0\uff0c\u800c\u662f\u6279\u91cf\u66f4\u65b0\uff0c\u6b64\u65f6 tail \u843d\u540e\u4e8e head\uff0c\n             \/\/   \u8fd8\u53ef\u80fd\u5373\u4f7f\u66f4\u65b0\u4e86\u4e5f\u53ef\u80fd\u53c8\u843d\u540e\u4e86\uff09\n            p = (t != (t = tail)) ? t : head;\n        else\n             \/\/ \u7ed3\u70b9 p \u4ecd\u7136\u5728\u961f\u5217\u4e0a\uff0c\u4e14\u4e0d\u662f\u6700\u540e\u7ed3\u70b9\uff0cp \u5411\u524d\u79fb\u3002\n             \/\/ \u5728\u4e24\u8df3\u4e4b\u540e\u68c0\u6d4b tail \u7684\u66f4\u65b0\u3002\n            p = (p != t &amp;&amp; t != (t = tail)) ? t : q;\n    }\n}\n<\/code><\/pre>\n<h4>poll \u64cd\u4f5c<\/h4>\n<p>\u83b7\u53d6\u5e76\u79fb\u9664\u6b64\u961f\u5217\u7684\u5934\uff0c\u5982\u679c\u6b64\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56de null\u3002<\/p>\n<pre><code class=\"java\">public E poll() {\n    restartFromHead:\n    for (;;) {\n        for (Node&lt;E&gt; h = head, p = h, q;;) {\n            E item = p.item;\n\n            if (item != null &amp;&amp; p.casItem(item, null)) {\n                   \/\/ \u627e\u5230\u5f53\u524d\u7b2c\u4e00\u4e2a\u5b58\u6d3b\u7ed3\u70b9\uff0c\u5e76\u4ece\u961f\u5217\u79fb\u9664\u6210\u529f\u3002\n                   \/\/ \u6279\u91cf\u66f4\u65b0 head\u3002\n                if (p != h) \/\/ hop two nodes at a time\n                      \/\/ \u57fa\u4e8e\u4e0d\u53d8\u5f0f\uff1ahead != null\n                    updateHead(h, ((q = p.next) != null) ? q : p);\n                return item;\n            }\n            else if ((q = p.next) == null) {\n                   \/\/ p \u662f\u6700\u540e\u7ed3\u70b9\uff0c\u4e14 p \u7684item\u5df2\u51fa\u961f\u5217\uff0c\u8bbe\u7f6e p \u4e3a\u5934\u7ed3\u70b9\u3002\n                   \/\/ \u7a7a\u961f\u5217\uff0c\u8fd4\u56denull\u3002\n                updateHead(h, p);\n                return null ;\n            }\n            else if (p == q)\n                   \/\/ p \u5df2\u4ece\u961f\u5217\u79fb\u9664\uff0c\u91cd\u65b0\u4ece head \u5f00\u59cb\u3002\n                continue restartFromHead;\n            else\n                   \/\/ \u7ed3\u70b9 p \u8fd8\u5728\u961f\u5217\uff0c\u4f46 p.item \u5df2\u51fa\u961f\uff0c\u524d\u79fb\u3002\n                p = q;\n        }\n    }\n}\n<\/code><\/pre>\n<h4>\u53d6\u540e\u7ee7\u64cd\u4f5c<\/h4>\n<p>\u5728\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\uff0c\u8fd4\u56de\u67d0\u4e2a\u7ed3\u70b9\u7684\u540e\u7ee7\u3002<\/p>\n<pre><code class=\"java\">\/*\n * \u8fd4\u56de p \u7684\u540e\u7ee7\uff0c\u5982\u679c p \u5df2\u88ab\u79fb\u9664\uff0c\u5219\u8fd4\u56de head\u3002\n *\/\nfinal Node&lt;E&gt; succ(Node&lt;E&gt; p) {\n    Node&lt;E&gt; next = p.next;\n    return (p == next) ? head : next;\n}\n<\/code><\/pre>\n<h4>size \u64cd\u4f5c<\/h4>\n<p>\u8fd4\u56de\u6b64\u961f\u5217\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u3002\u5982\u679c\u6b64\u961f\u5217\u5305\u542b\u7684\u5143\u7d20\u6570\u5927\u4e8e Integer.MAX_VALUE\uff0c\u5219\u8fd4\u56de Integer.MAX_VALUE\u3002\u786e\u5b9a\u5f53\u524d\u7684\u5143\u7d20\u6570\u9700\u8981\u8fdb\u884c\u4e00\u6b21\u82b1\u8d39 O(n) \u65f6\u95f4\u7684\u904d\u5386\u3002<\/p>\n<pre><code class=\"java\">public int size() {\n    int count = 0;\n    for (Node&lt;E&gt; p = first(); p != null; p = succ(p))\n        if (p.item != null)\n            \/\/ Collection.size() spec says to max out\n            if (++count == Integer.MAX_VALUE)\n                break;\n    return count;\n}\n<\/code><\/pre>\n<h3>QA<\/h3>\n<ul>\n<li>\n<p>Q\uff1a\u4e3a\u4ec0\u4e48\u8981\u5b9a\u4e49\u4e0d\u53d8\u5f0f\u3001\u53ef\u53d8\u5f0f\uff1f<br \/>\n A\uff1a\u4e0d\u53d8\u5f0f\u7528\u4e8e\u786e\u4fdd\u961f\u5217\u5728\u64cd\u4f5c\u5f00\u59cb\u4e4b\u524d\u3001\u5b8c\u6210\u4e4b\u540e\u5904\u4e8e\u6b63\u786e\u4e00\u81f4\u7684\u72b6\u6001\u3002\u53ef\u53d8\u5f0f\u5141\u8bb8\u961f\u5217\u5728\u64cd\u4f5c\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\u5904\u4e8e\u4e0d\u4e00\u81f4\u72b6\u6001\uff0c\u4e3a\u7684\u662f\u63d0\u9ad8\u5e76\u53d1\u6027\uff0c\u5f53\u7136\u4e5f\u662f\u6709\u4ee3\u4ef7\u7684\uff0c\u5927\u591a\u6570\u64cd\u4f5c\u65b9\u6cd5\u7684\u4ee3\u7801\u90fd\u662f\u5728\u5904\u7406\u53ef\u53d8\u5f0f\u7684\u60c5\u51b5\u3002<\/p>\n<\/li>\n<li>\n<p>Q\uff1a\u4e3a\u4ec0\u4e48\u4ee5 <code>node.next == null<\/code> \u4f5c\u4e3a\u5c3e\u7ed3\u70b9\u7684\u5224\u65ad\u6761\u4ef6\uff1f<br \/>\n A\uff1a\u5982\u679c\u4ee5 tail \u6307\u5411\u7684\u7ed3\u70b9\u4f5c\u4e3a\u5c3e\u7ed3\u70b9\u7684\u5224\u65ad\u6761\u4ef6\uff0c\u90a3\u4e48\u5728\u66f4\u65b0\u5c3e\u7ed3\u70b9\u7684 next \u5c5e\u6027 \u4e0e \u628a\u65b0\u7ed3\u70b9\u8bbe\u7f6e\u4e3a tail \u4e4b\u95f4\u5c31\u4f1a\u5f62\u6210\u4e00\u4e2a\u540c\u6b65\u533a\uff0c\u5728\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6210\u529f\u4e4b\u540e\u3001\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u5b8c\u6210\u4e4b\u524d\uff0c\u6240\u6709\u7684\u7ebf\u7a0b\u90fd\u4e0d\u80fd\u8fdb\u884c\u6dfb\u52a0\u64cd\u4f5c\u3002\u4ee5 <code>node.next == null<\/code> \u4f5c\u4e3a\u5c3e\u7ed3\u70b9\u7684\u5224\u65ad\u6761\u4ef6\uff0c\u90a3\u4e48\u9700\u8981\u540c\u6b65\u7684\u8303\u56f4\u5c31\u662fCAS\u66f4\u65b0\u5c3e\u7ed3\u70b9\uff0c\u800c\u8fd9\u53ea\u662f\u4e00\u4e2a\u539f\u5b50\u64cd\u4f5c\uff0c\u6240\u6709\u7ebf\u7a0b\u5931\u8d25\u540e\u90fd\u53ef\u4ee5\u7acb\u5373\u91cd\u8bd5\u3002<\/p>\n<\/li>\n<li>\n<p>Q\uff1ahead\u3001tail \u4e3a\u4ec0\u4e48\u90fd\u4e0d\u80fd\u662f null \uff1f<br \/>\n A\uff1a\u5982\u679c head\u3001tail \u5141\u8bb8\u662fnull\uff0c\u90a3\u4e48\u8fdb\u884c\u6dfb\u52a0\u3001\u79fb\u9664\u64cd\u4f5c\u65f6\uff0c\u5c31\u9700\u8981\u5bf9 head\u3001tail \u662f\u5426\u4e3a null \u8fdb\u884c\u5224\u65ad\uff0c\u4f7f\u6bcf\u4e2a\u64cd\u4f5c\u90fd\u4f9d\u8d56\u4e8e\u4e24\u4e2a\u53d8\u91cf\uff0c\u8fd9\u4f1a\u4f7f\u64cd\u4f5c\u7684\u72b6\u6001\u7ba1\u7406\u975e\u5e38\u590d\u6742\u3002\u5e76\u53d1\u7f16\u7a0b\u672c\u8d28\u5c31\u662f\u5bf9\u72b6\u6001\u7684\u7ba1\u7406\uff0c\u72b6\u6001\u8d8a\u5c11\uff0c\u8d8a\u5bb9\u6613\u5b9e\u73b0\u5e76\u53d1\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u56db\u3001\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li>JDK 1.7.0_10 \u6e90\u7801<\/li>\n<li><a href=\"http:\/\/www.ibm.com\/developerworks\/cn\/java\/j-lo-concurrent\/index.html\">\u975e\u963b\u585e\u7b97\u6cd5\u5728\u5e76\u53d1\u5bb9\u5668\u4e2d\u7684\u5b9e\u73b0<\/a><\/li>\n<li><a href=\"http:\/\/ifeve.com\/concurrentlinkedqueue\/\">\u804a\u804a\u5e76\u53d1\uff08\u516d\uff09ConcurrentLinkedQueue\u7684\u5b9e\u73b0\u539f\u7406\u5206\u6790<\/a><\/li>\n<\/ul>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>java.util.concurrent.ConcurrentLinkedQue &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/concurrent\/20140108\/701\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[110,148],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/701"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=701"}],"version-history":[{"count":3,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/701\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}