{"id":5263,"date":"2021-08-15T20:13:52","date_gmt":"2021-08-15T12:13:52","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=5263"},"modified":"2021-08-15T20:13:52","modified_gmt":"2021-08-15T12:13:52","slug":"%e9%9d%a2%e8%af%95%e5%ae%98%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88longadder%e6%80%a7%e8%83%bd%e6%af%94long%e8%bf%98%e5%bf%ab","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=5263","title":{"rendered":"\u9762\u8bd5\u5b98\uff1a\u4e3a\u4ec0\u4e48LongAdder\u6027\u80fd\u6bd4long\u8fd8\u5feb"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6700\u8fd1\u4e00\u6bb5\u65f6\u95f4\u7684\u8bd5\u9a8c\uff0c\u6211\u53d1\u73b0\u5468\u516d\u5468\u65e5\u5199\u539f\u521b\uff0c\u6ca1\u591a\u5c11\u4eba\u770b\uff01<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/yyc0.png\" alt=\"\u4e1a\u4f59\u8349\u7d2f\u8ba1\u539f\u521b444\u7bc7\" \/><figcaption>\u4e1a\u4f59\u8349\u7d2f\u8ba1\u539f\u521b444\u7bc7<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0c\u4ee5\u540e\u5c3d\u91cf\u5c06\u5468\u516d\u5468\u65e5\u5199\u7684\u539f\u521b\u6587\u7ae0\uff0c\u653e\u5728\u5468\u4e00\u548c\u5468\u4e94\u4e4b\u95f4\u53d1\u5e03\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u7a0b\u5e8f\u5458\u9700\u8981\u7ecf\u5e38\u5173\u6ce8\u4e00\u4e9b\u56fd\u5916\u5927\u795e\u7ea7\u522b\u7a0b\u5e8f\u5458\u7684\u52a8\u5411\u3002\u6bd4\u5982\uff0c\u6211\u7ecf\u5e38\u5173\u6ce8\uff1aDisruptor\u3001Doung Lea\u3001Martin Fowler\u7b49\u7b49\u3002\u901a\u8fc7\u4ed6\u4eec\u7684\u6700\u65b0\u6587\u7ae0\u548c\u8a00\u8bba\uff0c\u6211\u4f1a\u83b7\u5f97\u4e0d\u5c11\u7684\u6709\u7528\u4fe1\u606f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51e0\u5e74\u524d\uff08\u5177\u4f53\u65f6\u95f4\u5fd8\u8bb0\u4e86\uff09\u6211 Watch \u4e86 Hystrix\uff0c\u6709\u4e00\u5929\u53d1\u73b0\uff0cHystrix \u5728\u66f4\u65b0\u4ee3\u7801\u4e2d\uff0c\u5c06 AtomicLong \u66ff\u6362\u6210\u4e86 LongAdder\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u6765\uff0c\u6211\u624d\u660e\u767d Hystrix \u9700\u8981\u6839\u636e\u8fc7\u53bb\u4e00\u6bb5\u65f6\u95f4\u5185\u5931\u8d25\u7684\u8bf7\u6c42\u6b21\u6570\u6765\u5224\u65ad\u662f\u5426\u6253\u5f00\u7194\u65ad\u5f00\u5173\u3002\u6240\u4ee5\u5b83\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u65f6\u95f4\u7a97\u53e3\uff0c\u5e76\u4e0d\u65ad\u5411\u8be5\u7a97\u53e3\u4e2d\u7d2f\u52a0\u5931\u8d25\u8bf7\u6c42\u6b21\u6570\uff0c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u4e00\u822c\u4f1a\u4f7f\u7528 AtomicLong\uff0c\u4f46\u662f Hystrix \u4e2d\u76ee\u524d\u662f LongAdder\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u7279\u5730\u67e5\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0 Hystrix \u548c Java8 \u4e2d\u7684 LongAdder \u8fd8\u6709\u4e00\u4e9b\u7ec6\u5fae\u5dee\u522b\uff0c\u4e0d\u8fc7\u6574\u4f53\u601d\u8def\u662f\u4e00\u6837\u7684\uff0c\u4e0b\u9762\u7684\u5206\u6790\u90fd\u662f\u4ee5 jdk \u4e3a\u51c6\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48 Hystrix \u4f7f\u7528 LongAdder \u800c\u4e0d\u662f AtomicLong \u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 java8 \u4e2d LongAdder \u7684 Java doc \u4e2d\u6709\u4ee5\u4e0b\u8bf4\u660e\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>This class is usually preferable to AtomicLong when multiple threads update a common sum that is used for purposes such as collecting statistics, not for fine-grained synchronization control. Under low update contention, the two classes have similar characteristics. But under high contention, expected throughput of this class is significantly higher, at the expense of higher space consumption.\u275e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5b58\u5728\u9ad8\u5ea6\u7ade\u4e89\u7684\u6761\u4ef6\u4e0b\uff0cLongAdder \u7684\u6027\u80fd\u4f1a\u8fdc\u8fdc\u597d\u4e8e AtomicLong\uff0c\u4e0d\u8fc7\u4f1a\u6d88\u8017\u66f4\u591a\u7a7a\u95f4\u3002<code>\u9ad8\u5ea6\u7ade\u4e89\u5f53\u7136\u662f\u6307\u5728\u591a\u7ebf\u7a0b\u6761\u4ef6\u4e0b\u7684\u9ad8\u5e76\u53d1\u573a\u666f<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u77e5\u9053 AtomicLong \u662f\u901a\u8fc7 cas \u6765\u66f4\u65b0\u503c\u7684\uff0c\u6309\u7406\u8bf4\u662f\u5f88\u5feb\u7684\u3002\u4f46\u662f LongAdder \u4e3a\u4ec0\u4e48\u4f1a\u6bd4\u5b83\u66f4\u5feb\uff0c\u662f\u8fd8\u6709\u5176\u4ed6\u4ec0\u4e48\u66f4\u5feb\u7684\u624b\u6bb5\u5417\uff1f\u5148\u4e0d\u7ba1\u8fd9\u4e9b\uff0c\u76f4\u63a5\u5b9e\u9a8c\u4e00\u4e0b\uff0c\u770b\u662f\u4e0d\u662f\u771f\u7684\u66f4\u5feb\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/yyc1.png\" alt=\"\" \/><figcaption>LongAdder vs AtomicLong \u6027\u80fd\u6bd4\u8f83<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u6027\u80fd\u5bf9\u6bd4<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AtomicLong\u3001LongAdder\u3001long \u7684\u6027\u80fd\u6d4b\u8bd5\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TestAtomic {\n\n    private static final int TASK_NUM = 1000;\n    private static final int INCREMENT_PER_TASK = 10000;\n    private static final int REPEAT = 10;\n\n    private static long l = 0;\n\n    public static void main(String[] args) throws Exception {\n        repeatWithStatics(REPEAT, () -&gt; testAtomicLong());\n        repeatWithStatics(REPEAT, () -&gt; testLongAdder());\n        repeatWithStatics(REPEAT, () -&gt; testLong());\n    }\n\n    public static void testAtomicLong() {\n        AtomicLong al = new AtomicLong(0);\n        execute(TASK_NUM, () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; al.incrementAndGet()));\n    }\n\n    public static void testLong() {\n        l = 0;\n        execute(TASK_NUM, () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; l++));\n    }\n\n    public static void testLongAdder() {\n        LongAdder adder = new LongAdder();\n        execute(TASK_NUM, () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; adder.add(1)));\n    }\n\n    public static void repeatWithStatics(int n, Runnable runnable) {\n        long[] elapseds = new long[n];\n\n        ntimes(n).forEach(x -&gt; {\n            long start = System.currentTimeMillis();\n            runnable.run();\n            long end = System.currentTimeMillis();\n            elapseds[x] = end - start;\n        });\n\n        System.out.printf(\"total: %d, %s\\n\", Arrays.stream(elapseds).sum(), Arrays.toString(elapseds));\n    }\n\n    private static void execute(int n, Runnable task) {\n        try {\n            CountDownLatch latch = new CountDownLatch(n);\n            ExecutorService service = Executors.newFixedThreadPool(100);\n\n            Runnable taskWrapper = () -&gt; {\n                task.run();\n                latch.countDown();\n            };\n\n            service.invokeAll(cloneTask(n, taskWrapper));\n            latch.await();\n            service.shutdown();\n        } catch (Exception e) {}\n    }\n\n    private static Collection&lt;Callable&lt;Void&gt;&gt; cloneTask(int n, Runnable task) {\n        return ntimes(n).mapToObj(x -&gt; new Callable&lt;Void&gt;() {\n            @Override\n            public Void call() throws Exception {\n                task.run();\n                return null;\n            }\n        }).collect(Collectors.toList());\n    }\n\n    private static void repeat(int n, Runnable runnable) {\n        ntimes(n).forEach(x -&gt; runnable.run());\n    }\n\n    private static IntStream ntimes(int n) {\n        return IntStream.range(0, n);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u662f\u7528 1000 \u4e2a\u5e76\u53d1\u4efb\u52a1\uff0c\u6bcf\u4e2a\u4efb\u52a1\u5bf9\u6570\u636e\u7d2f\u52a0 10000 \u6b21\uff0c\u6bcf\u4e2a\u5b9e\u9a8c\u6d4b\u8bd5 10 \u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>total: 1939, [258, 196, 200, 174, 186, 178, 204, 189, 185, 169]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>total: 613, [57, 45, 47, 53, 69, 61, 80, 67, 64, 70]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>total: 1131, [85, 67, 77, 81, 280, 174, 108, 67, 99, 93]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u5f80\u4e0b\u4f9d\u6b21\u662f AtomicLong\uff0cLongAdder\uff0clong\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u7ed3\u679c\u80fd\u770b\u5230 LongAdder \u786e\u5b9e\u6027\u80fd\u9ad8\u4e8e AtomicLong\uff0c\u4e0d\u8fc7\u8fd8\u6709\u4e00\u4e2a\u8ba9\u6211\u975e\u5e38\u5403\u60ca\u7684\u7ed3\u679c\uff0c\u5c31\u662f LongAdder \u7adf\u7136\u6bd4\u76f4\u63a5\u7d2f\u52a0 long \u8fd8\u5feb\uff08\u5f53\u7136\u76f4\u63a5\u7d2f\u52a0 long \u6700\u7ec8\u5f97\u5230\u7684\u7ed3\u679c\u662f\u9519\u8bef\u7684\uff0c\u56e0\u4e3a\u6ca1\u6709\u540c\u6b65\uff09\u3002\u8fd9\u4e2a\u6709\u4e9b\u53cd\u5e38\u8bc6\u4e86\uff0c\u5176\u5b9e\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86\u4e00\u4e9b\u9690\u85cf\u7684\u95ee\u9898\uff0c\u5c31\u662f cache \u7684 false sharing\uff0c\u56e0\u4e3a\u5e73\u65f6\u7f16\u7a0b\u65f6\u4e0d\u592a\u4f1a\u5173\u6ce8 cache \u8fd9\u4e9b\uff0c\u6240\u4ee5\u78b0\u5230\u8fd9\u4e2a\u7ed3\u679c\u4f1a\u51fa\u4e4e\u9884\u6599\uff0c\u5f97\u4f1a\u518d\u8be6\u7ec6\u7684\u89e3\u91ca\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LongAdder \u6e90\u7801\u5206\u6790<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u6765\u5206\u6790\u4e00\u4e0b LongAdder \u4e3a\u4ec0\u4e48\u4f1a\u6bd4 AtomicLong \u5feb\uff0c\u662f\u4e0d\u662f\u7528\u5230\u4e86\u4ec0\u4e48\u6bd4 cas \u8fd8\u5feb\u7684\u4e1c\u897f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">LongAdder \u7684\u7236\u7c7b Striped64 \u7684\u6ce8\u91ca\u4e2d\u5df2\u7ecf\u5c06\u6574\u4e2a\u7c7b\u7684\u8bbe\u8ba1\u8bb2\u7684\u5f88\u6e05\u695a\u7684\u4e86\uff0c\u7c7b\u4e2d\u4e3b\u8981\u7ef4\u62a4\u4e24\u4e2a\u503c\uff0c\u4e00\u4e2a long \u578b\u7684 base \u5c5e\u6027\uff0c\u4e00\u4e2a Cell \u6570\u7ec4\uff0c\u5b83\u4eec\u503c\u7684\u548c\u624d\u662f\u771f\u6b63\u7684\u7ed3\u679c\u3002Cell \u662f\u5bf9 long \u7684\u4e00\u4e2a\u5305\u88c5\uff0c\u4e3a\u4ec0\u4e48\u5c06 long \u5305\u88c5\u8d77\u6765\uff0c\u731c\u6d4b\u6709\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u53ef\u4ee5\u5728\u7c7b\u4e2d\u6dfb\u52a0 padding \u6570\u636e\uff0c\u907f\u514d false sharing<\/li><li>\u5305\u88c5\u8d77\u6765\u624d\u597d\u4f7f\u7528 cas\u3002<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">LongAdder.add \u7684\u6d41\u7a0b\u7b80\u5355\u63cf\u8ff0\u5c31\u662f\uff0c\u5148\u5c1d\u8bd5\u901a\u8fc7 cas \u4fee\u6539 base\uff0c\u6210\u529f\u5219\u8fd4\u56de\uff0c\u5931\u8d25\u5219\u6839\u636e\u5f53\u524d\u7ebf\u7a0b hash \u503c\u4ece Cell \u6570\u7ec4\u4e2d\u9009\u62e9\u4e00\u4e2a Cell\uff0c\u7136\u540e\u5411 Cell \u4e2d add \u6570\u636e\u3002Cell \u6570\u7ec4\u662f\u52a8\u6001\u589e\u957f\u7684\uff0c\u5e76\u4e14\u662f\u7528\u65f6\u624d\u521d\u59cb\u5316\u7684\uff0c\u8fd9\u662f\u4e3a\u4e86\u907f\u514d\u5360\u7528\u8fc7\u591a\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u770b\u5230\u6ce8\u91ca\u5927\u6982\u80fd\u731c\u5230\u4e3a\u4ec0\u4e48\u5feb\u4e86\uff0cLongAdder \u4ecd\u7136\u7528\u7684 cas\uff0c\u5feb\u662f\u56e0\u4e3a\u5728\u9ad8\u5ea6\u7ade\u4e89\u7684\u6761\u4ef6\u4e0b\uff0c\u5bf9\u4e00\u4e2a\u503c\u8fdb\u884c\u4fee\u6539\uff0c\u51b2\u7a81\u7684\u6982\u7387\u5f88\u9ad8\uff0c\u9700\u8981\u4e0d\u65ad cas\uff0c\u5bfc\u81f4\u65f6\u95f4\u6d6a\u8d39\u5728\u5faa\u73af\u4e0a\uff0c\u5982\u679c\u5c06\u4e00\u4e2a\u503c\u62c6\u5206\u4e3a\u591a\u4e2a\u503c\uff0c\u5206\u6563\u538b\u529b\uff0c\u90a3\u4e48\u6027\u80fd\u5c31\u4f1a\u6709\u6240\u63d0\u9ad8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u6765\u770b\u6e90\u7801\uff0c\u8fdb\u5165 LongAdder \u7684 add \u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void add(long x) {\n    Cell[] as; long b, v; int m; Cell a;\n    if ((as = cells) != null || !casBase(b = base, b + x)) {\n        boolean uncontended = true;\n        if (as == null || (m = as.length - 1) &lt; 0 ||\n            (a = as[getProbe() &amp; m]) == null ||\n            !(uncontended = a.cas(v = a.value, v + x)))\n            longAccumulate(x, null, uncontended);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u5148\u5bf9 base \u8fdb\u884c cas \u64cd\u4f5c\uff0c\u7136\u540e\u5224\u65ad Cell \u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\uff0c\u4e0d\u4e3a\u7a7a\u5219\u6839\u636e\u5f53\u524d\u7ebf\u7a0b probe \u503c\uff08\u7c7b\u4f3c hash \u503c\uff09\u9009\u62e9 Cell \u5e76\u8fdb\u884c cas\uff0c\u90fd\u4e0d\u6210\u529f\u8fdb\u5165 longAccumulate \u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>final void longAccumulate(long x, LongBinaryOperator fn,\n                          boolean wasUncontended) {\n    int h;\n    if ((h = getProbe()) == 0) {\n        ThreadLocalRandom.current(); \n        h = getProbe();\n        wasUncontended = true;\n    }\n    boolean collide = false;\n    for (;;) {\n        Cell[] as; Cell a; int n; long v;\n        if ((as = cells) != null &amp;&amp; (n = as.length) &gt; 0) {\/\/ (1)\n            if ((a = as[(n - 1) &amp; h]) == null) {\/\/ (1.1)\n                if (cellsBusy == 0) {  \n                    Cell r = new Cell(x); \n                    if (cellsBusy == 0 &amp;&amp; casCellsBusy()) {\n                        boolean created = false;\n                        try {\n                            Cell[] rs; int m, j;\n                            if ((rs = cells) != null &amp;&amp;\n                                (m = rs.length) &gt; 0 &amp;&amp;\n                                rs[j = (m - 1) &amp; h] == null) {\n                                rs[j] = r;\n                                created = true;\n                            }\n                        } finally {\n                            cellsBusy = 0;\n                        }\n                        if (created)\n                            break;\n                        continue;   \n                    }\n                }\n                collide = false;\n            }\n            else if (!wasUncontended)  \n                wasUncontended = true; \n            else if (a.cas(v = a.value, ((fn == null) ? v + x :\n                                         fn.applyAsLong(v, x)))) \/\/ (1.2)\n                break;\n            else if (n &gt;= NCPU || cells != as)\n                collide = false;  \n            else if (!collide)\n                collide = true;\n            else if (cellsBusy == 0 &amp;&amp; casCellsBusy()) {\/\/ (1.3)\n                try {\n                    if (cells == as) { \n                        Cell[] rs = new Cell[n &lt;&lt; 1];\n                        for (int i = 0; i &lt; n; ++i)\n                            rs[i] = as[i];\n                        cells = rs;\n                    }\n                } finally {\n                    cellsBusy = 0;\n                }\n                collide = false;\n                continue;           \n            }\n            h = advanceProbe(h);\n        }\n        else if (cellsBusy == 0 &amp;&amp; cells == as &amp;&amp; casCellsBusy()) {\/\/ (2)\n            boolean init = false;\n            try {                  \n                if (cells == as) {\n                    Cell[] rs = new Cell[2];\n                    rs[h &amp; 1] = new Cell(x);\n                    cells = rs;\n                    init = true;\n                }\n            } finally {\n                cellsBusy = 0;\n            }\n            if (init)\n                break;\n        }\n        else if (casBase(v = base, ((fn == null) ? v + x :\n                                    fn.applyAsLong(v, x))))\/\/ (3)\n            break;                          \n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Cell \u6570\u7ec4\u4e0d\u4e3a\u7a7a\u65f6\u8fdb\u5165<code>\u5206\u652f(1)<\/code>\uff0c\u5982\u679c\u6839\u636e\u5f53\u524d\u7ebf\u7a0b hash \u83b7\u5f97\u7684 Cell \u4e3a null\uff0c\u5219\u8fdb\u5165<code>(1.1)<\/code>\u5f00\u59cb\u5b9e\u4f8b\u5316\u8be5 Cell\uff0c\u5426\u5219\u8fdb\u5165<code>(1.2)<\/code>\u5bf9 Cell \u8fdb\u884c cas\uff0c\u4e0d\u6210\u529f\u7684\u8bdd\u8868\u793a\u51b2\u7a81\u6bd4\u8f83\u591a\uff0c\u5f00\u59cb\u8fdb\u5165<code>(1.3)<\/code>\u5bf9 Cell \u6570\u7ec4\u6269\u5bb9\u4e86\uff0ccellsBusy \u662f\u7528 cas \u5b9e\u73b0\u7684\u4e00\u4e2a spinlock\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cell \u6570\u7ec4\u4e3a\u7a7a\u4e14\u83b7\u53d6\u5230 cellsBusy \u65f6\u8fdb\u5165\u5206\u652f<code>(2)<\/code>\uff0c\u5f00\u59cb\u521d\u59cb\u5316 Cell \u6570\u7ec4\uff1b<br>\n<code>\u5206\u652f(1)\u548c(2)<\/code>\u90fd\u8fdb\u4e0d\u53bb\uff0c\u6ca1\u529e\u6cd5\uff0c\u53ea\u80fd\u518d\u6b21\u5bf9 base \u8fdb\u884c cas\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u53ea\u662f\u5bf9\u6e90\u7801\u505a\u4e86\u7c97\u7565\u7684\u5206\u6790\uff0c\u8fd9\u4e9b\u6211\u4eec\u90fd\u4e0d\u9700\u8981\u8f83\u771f\u53bb\u5f04\u7684\u975e\u5e38\u6e05\u695a\uff0c\u6bd5\u7adf\u4e16\u754c\u4e0a\u53ea\u6709\u4e00\u4e2a Doug Lea\uff0c\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053 LongAdder \u662f\u600e\u4e48\u6bd4 AtomicLong \u5feb\u7684\u5c31\u884c\uff0c\u5b9e\u9645\u5c31\u662f\u7528\u591a\u4e2a long \u6765\u5206\u62c5\u538b\u529b\uff0c\u4e00\u7fa4\u4eba\u5230\u5341\u4e2a\u76d8\u5b50\u91cc\u5939\u83dc\u5f53\u7136\u6bd4\u5230\u4e00\u4e2a\u76d8\u5b50\u91cc\u5939\u83dc\u51b2\u7a81\u5c0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5316\u7248\u7684 LongAdder<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u77e5\u9053\u4e86\u539f\u7406\uff0c\u90a3\u6211\u4eec\u5c31\u81ea\u5df1\u6765\u5b9e\u73b0\u4e00\u4e2a\u7b80\u964b\u7684 LongAdder\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MyLong {\n    private static final int LEN = 2 &lt;&lt; 5;\n\n    private AtomicLong[] atomicLongs = new AtomicLong[LEN];\n    public MyLong() {\n        for (int i = 0; i &lt; LEN; ++i) {\n            atomicLongs[i] = new AtomicLong(0);\n        }\n    }\n\n    public void add(long l) {\n        atomicLongs[hash(Thread.currentThread()) &amp; (LEN - 1)].addAndGet(l);\n    }\n\n    public void increment() {\n        add(1);\n    }\n\n    public long get() {\n        return Arrays.stream(atomicLongs).mapToLong(al -&gt; al.get()).sum();\n    }\n\n    \/\/ \u4ece HashMap \u91cc\u6284\u8fc7\u6765\u7684\n    private static final int hash(Object key) {\n        int h;\n        return (key == null) ? 0 : (h = key.hashCode()) ^ (h &gt;&gt;&gt; 16);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6700\u4e0a\u9762\u7684 TestAtomic \u7c7b\u4e2d\u52a0\u4e0a\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String[] args) throws Exception {\n    repeatWithStatics(REPEAT, () -&gt; testAtomicLong());\n    repeatWithStatics(REPEAT, () -&gt; testLongAdder());\n    repeatWithStatics(REPEAT, () -&gt; testLong());\n    repeatWithStatics(REPEAT, () -&gt; testMyLong());\n}\n \npublic static void testMyLong() {\n    MyLong myLong = new MyLong();\n    execute(TASK_NUM, () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; myLong.increment()));\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total:\u00a01907,\u00a0[176,\u00a0211,\u00a0192,\u00a0182,\u00a0195,\u00a0173,\u00a0199,\u00a0229,\u00a0184,\u00a0166]\ntotal:\u00a0641,\u00a0[67,\u00a050,\u00a045,\u00a053,\u00a073,\u00a058,\u00a080,\u00a063,\u00a069,\u00a083]\ntotal:\u00a0947,\u00a0[90,\u00a082,\u00a070,\u00a072,\u00a087,\u00a078,\u00a0136,\u00a0107,\u00a077,\u00a0148]\ntotal:\u00a0670,\u00a0[81,\u00a080,\u00a073,\u00a067,\u00a057,\u00a094,\u00a062,\u00a049,\u00a057,\u00a050]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\u6027\u80fd\u6bd4 AtomicLong \u597d\u591a\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48 LongAdder \u6bd4\u76f4\u63a5\u7d2f\u52a0 long \u8fd8\u5feb<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u89e3\u91ca\u4e86 LongAdder \u6bd4 AtomicLong \u5feb\uff0c\u4f46\u662f\u4e3a\u4ec0\u4e48\u5b83\u8fd8\u4f1a\u6bd4 long \u5feb\uff1f\u89e3\u7b54\u8fd9\u4e2a\u95ee\u9898\u4e4b\u524d\u8981\u5148\u4ecb\u7ecd\u4f2a\u5171\u4eab\u7684\u6982\u5ff5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f2a\u5171\u4eab(false sharing)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8ba1\u7b97\u673a\u4e2d\u5bfb\u5740\u662f\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff0c\u4f46\u662f cache \u4ece\u5185\u5b58\u4e2d\u590d\u5236\u6570\u636e\u662f\u4ee5\u884c\u4e3a\u5355\u4f4d\u7684\uff0c\u4e00\u4e2a\u884c\u4f1a\u5305\u542b\u591a\u4e2a\u5b57\u8282\uff0c\u4e00\u822c\u4e3a 64 \u5b57\u8282\uff0c\u6bcf\u4e2a CPU \u6709\u81ea\u5df1\u7684 L1\u3001L2 cache\uff0c\u73b0\u5728\u6709\u4e24\u4e2a\u53d8\u91cfx\u3001y \u5728\u540c\u4e00\u884c\u4e2d\uff0c\u5982\u679c CPU1 \u4fee\u6539 x\uff0c\u7f13\u5b58\u4e00\u81f4\u6027\u8981\u6c42\u6570\u636e\u4fee\u6539\u9700\u8981\u9a6c\u4e0a\u53cd\u5e94\u5230\u5176\u4ed6\u5bf9\u5e94\u526f\u672c\u4e0a\uff0cCPU2 cache \u5bf9\u5e94\u884c\u91cd\u65b0\u5237\u65b0\uff0c\u7136\u540e CPU2 \u624d\u80fd\u8bbf\u95ee y\uff0c\u5982\u679c CPU1 \u4e00\u76f4\u4fee\u6539 x\uff0cCPU2 \u4e00\u76f4\u8bbf\u95ee y\uff0c\u90a3\u4e48 CPU2 \u5f97\u4e00\u76f4\u7b49\u5230 cache \u5237\u65b0\u540e\u624d\u80fd\u8bbf\u95ee y\uff0c\u5e26\u6765\u6027\u80fd\u4e0b\u964d\uff0c\u4ea7\u751f\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u6709\u4e24\u65b9\u9762\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>x\u3001y \u4f4d\u4e8e\u540c\u4e00\u884c<\/li><li>\u4e24\u4e2a CPU \u4f1a\u9891\u7e41\u7684\u8bbf\u95ee\u8fd9\u4e24\u4e2a\u6570\u636e\uff0c\u5982\u679c\u8fd9\u4e24\u4e2a\u6761\u4ef6\u5176\u4e2d\u4e00\u4e2a\u4e0d\u6210\u7acb\uff0c\u90a3\u5c31\u4e0d\u4f1a\u4ea7\u751f\u95ee\u9898\u3002\u66f4\u591a\u5173\u4e8e\u4f2a\u5171\u4eab\u7684\u6982\u5ff5\u5efa\u8bae\u5927\u5bb6\u81ea\u884c\u641c\u7d22\uff0c\u6216\u8005\u6211\u540e\u9762\u62bd\u65f6\u95f4\u5199\u6587\u7ae0\u3002<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u51b3\u529e\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e2\u7136\u8fd9\u4e2a\u95ee\u9898\u51fa\u73b0\u4e86\uff0c\u90a3\u80af\u5b9a\u662f\u6709\u89e3\u51b3\u529e\u6cd5\u7684\u3002\u4e00\u822c\u5c31\u662f\u6dfb\u52a0 padding \u6570\u636e\uff0c\u6765\u5c06 x\u3001y \u9694\u5f00\uff0c\u8ba9\u5b83\u4eec\u4e0d\u4f1a\u4f4d\u4e8e\u540c\u4e00\u884c\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u4e2d\u7684\u8bdd\uff0c\u5728 Java7 \u4e4b\u524d\u9700\u8981\u624b\u52a8\u6dfb\u52a0 padding \u6570\u636e\uff0c\u540e\u6765<a href=\"http:\/\/openjdk.java.net\/jeps\/142\">JEP 142<\/a>\u63d0\u6848\u63d0\u51fa\u5e94\u8be5\u4e3a\u7a0b\u5e8f\u5458\u63d0\u4f9b\u67d0\u79cd\u65b9\u5f0f\u6765\u6807\u660e\u54ea\u4e9b\u5b57\u6bb5\u662f\u4f1a\u5b58\u5728\u7f13\u5b58\u7ade\u4e89\u7684\uff0c\u5e76\u4e14\u865a\u62df\u673a\u80fd\u591f\u6839\u636e\u8fd9\u4e9b\u6807\u8bc6\u6765\u907f\u514d\u8fd9\u4e9b\u5b57\u6bb5\u4f4d\u4e8e\u540c\u4e00\u884c\u4e2d\uff0c\u7a0b\u5e8f\u5458\u4e0d\u7528\u518d\u624b\u52a8\u586b\u5145 padding \u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">@Contended \u5c31\u662f\u5e94 JEP 142 \u800c\u751f\u7684\uff0c\u5728\u5b57\u6bb5\u6216\u7c7b\u4e0a\u6807\u51c6\u8be5\u6ce8\u89e3\uff0c\u5c31\u8868\u793a\u7f16\u8bd1\u5668\u6216\u865a\u62df\u673a\u9700\u8981\u5728\u8fd9\u4e9b\u6570\u636e\u5468\u56f4\u6dfb\u52a0 padding \u6570\u636e\u3002@Contended \u5f97\u5177\u4f53\u7528\u6cd5\uff0c\u6211\u540e\u9762\u518d\u5199\u76f8\u5173\u8d44\u6599\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u5b9e\u9a8c\u4e00\u4e0b\u6765\u89c2\u5bdf false sharing\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TestContended {\n\n    private static int NCPU = Runtime.getRuntime().availableProcessors();\n    private static ForkJoinPool POOL = new ForkJoinPool(NCPU);\n    private static int INCREMENT_PER_TASK = 1000000;\n    private static final int REPEAT = 10;\n\n    private static long l = 0;\n\n    private static long l1 = 0;\n    private static long l2 = 0;\n\n    private static long cl1 = 0;\n    private static volatile long q0, q1, q2, q3, q4, q5, q6;\n    private static long cl2 = 0;\n\n    public static void main(String[] args) {\n        repeatWithStatics(REPEAT, () -&gt; testLongWithSingleThread());\n        repeatWithStatics(REPEAT, () -&gt; testLong());\n        repeatWithStatics(REPEAT, () -&gt; testTwoLong());\n        repeatWithStatics(REPEAT, () -&gt; testTwoContendedLong());\n    }\n\n    public static void testLongWithSingleThread() {\n        repeat(2 * INCREMENT_PER_TASK, () -&gt; l++);\n    }\n\n    public static void testLong() {\n        asyncExecute2Task(() -&gt; repeat(INCREMENT_PER_TASK, () -&gt; l++), () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; l++));\n    }\n\n    public static void testTwoLong() {\n        asyncExecute2Task(() -&gt; repeat(INCREMENT_PER_TASK, () -&gt; l1++), () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; l2++));\n    }\n\n    public static void testTwoContendedLong() {\n        asyncExecute2Task(() -&gt; repeat(INCREMENT_PER_TASK, () -&gt; cl1++), () -&gt; repeat(INCREMENT_PER_TASK, () -&gt; cl2++));\n    }\n\n    public static void repeatWithStatics(int n, Runnable runnable) {\n        long[] elapseds = new long[n];\n\n        ntimes(n).forEach(x -&gt; {\n            long start = System.currentTimeMillis();\n            runnable.run();\n            long end = System.currentTimeMillis();\n            elapseds[x] = end - start;\n        });\n\n        System.out.printf(\"total: %d, %s\\n\", Arrays.stream(elapseds).sum(), Arrays.toString(elapseds));\n    }\n\n    private static void asyncExecute2Task(Runnable task1, Runnable task2) {\n        try {\n            CompletableFuture.runAsync(task1, POOL)\n                    .thenCombine(CompletableFuture.runAsync(task2, POOL), (r1, r2) -&gt; 0).get();\n        } catch (Exception e) {}\n    }\n\n    private static void repeat(int n, Runnable runnable) {\n        ntimes(n).forEach(x -&gt; runnable.run());\n    }\n\n    private static IntStream ntimes(int n) {\n        return IntStream.range(0, n);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u8fd9\u91cc\u65f6\u624b\u5de5\u6dfb\u52a0\u4e86 padding \u6570\u636e\u3002\u76ee\u524d\u7f13\u5b58\u884c\u5927\u5c0f\u4e00\u822c\u4e3a 64 \u5b57\u8282\uff08\u4e5f\u53ef\u4ee5\u901a\u8fc7 CPUZ \u6765\u67e5\u770b\uff09\uff0c\u4e5f\u5c31\u662f\u586b\u5145 7 \u4e2a long \u5c31\u53ef\u4ee5\u5c06\u4e24\u4e2a long \u578b\u6570\u636e\u9694\u79bb\u5728\u4e24\u4e2a\u7f13\u5b58\u884c\u4e2d\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total:\u00a016,\u00a0[9,\u00a05,\u00a01,\u00a00,\u00a00,\u00a00,\u00a00,\u00a01,\u00a00,\u00a00]\ntotal:\u00a0232,\u00a0[35,\u00a035,\u00a033,\u00a024,\u00a025,\u00a023,\u00a013,\u00a015,\u00a015,\u00a014]\ntotal:\u00a0148,\u00a0[17,\u00a015,\u00a014,\u00a016,\u00a014,\u00a015,\u00a013,\u00a017,\u00a012,\u00a015]\ntotal:\u00a094,\u00a0[8,\u00a08,\u00a08,\u00a08,\u00a015,\u00a09,\u00a010,\u00a011,\u00a08,\u00a09]\u00a0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u5f80\u4e0b\u4f9d\u6b21\u4e3a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5355\u7ebf\u7a0b\u7d2f\u52a0\u4e00\u4e2a long\uff1b<\/li><li>\u4e24\u4e2a\u7ebf\u7a0b\u7d2f\u52a0\u4e00\u4e2a long\uff1b<\/li><li>\u4e24\u4e2a\u7ebf\u7a0b\u7d2f\u52a0\u4e24\u4e2a long\uff0c\u8fd9\u4e24\u4e2a long \u4f4d\u4e8e\u540c\u4e00\u7f13\u5b58\u884c\u4e2d\uff1b<\/li><li>\u4e24\u4e2a\u7ebf\u7a0b\u7d2f\u52a0\u4e24\u4e2a long\uff0c\u4e14\u5b83\u4eec\u4f4d\u4e8e\u4e0d\u540c\u7f13\u5b58\u884c\u4e2d\u3002<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u9762\u7684\u7ed3\u679c\u770b\uff0cpadding \u8fd8\u662f\u5f88\u6709\u6548\u7684\u3002\u7ed3\u679c 2 \u76f8\u6bd4\u4e8e 1\uff0c\u4e0d\u4ec5\u4f1a\u6709\u7ebf\u7a0b\u5207\u6362\u4ee3\u4ef7\u8fd8\u4f1a\u6709 false sharing \u95ee\u9898\uff0c\u5bf9\u4e8e\u7eaf\u8ba1\u7b97\u578b\u4efb\u52a1\u7ebf\u7a0b\u4e2a\u6570\u4e0d\u8981\u8d85\u8fc7 CPU \u4e2a\u6570\u3002\u4e0d\u8fc7\uff0c\u7ed3\u679c 2 \u548c 3 \u5dee\u8ddd\u6709\u70b9\u5927\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u731c\u6d4b\uff0c\u8fd9\u4e2a\u5e94\u8be5\u662f\u7c7b\u53d8\u91cf l1 \u548c l2 \u5df2\u7ecf\u4e0d\u662f\u540c\u4e00\u7f13\u5b58\u884c\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u5728 l2 \u540e\u518d\u589e\u52a0\u4e00\u4e2a\u53d8\u91cf long l3\u3002testTwoLong \u7684\u4e24\u4e2a\u7ebf\u7a0b\u65b9\u6cd5\u4fee\u6539\u4e3a l2++\uff0cl3++ \u5c31\u4f1a\u53d1\u73b0 testLong\u3001testTwoLong \u7684\u6267\u884c\u65f6\u95f4\u5dee\u4e0d\u591a\u4e00\u6837\u4e86\u8fdc\u5927\u4e8e testTwoContendedLong\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003\u8d44\u6599<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>LongAdder vs AtomicLong\uff1a<code><a rel=\"noreferrer noopener\" aria-label=\"http:\/\/blog.palominolabs.com\/2014\/02\/10\/java-8-performance-improvements-longadder-vs-atomiclong\/\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"http:\/\/blog.palominolabs.com\/2014\/02\/10\/java-8-performance-improvements-longadder-vs-atomiclong\/\" target=\"_blank\">http:\/\/blog.palominolabs.com\/2014\/02\/10\/java-8-performance-improvements-longadder-vs-atomiclong\/<\/a><\/code><\/li><li>atomic fetch-and-add vs compare-and-swap\uff1a<code><a href=\"https:\/\/blogs.oracle.com\/dave\/atomic-fetch-and-add-vs-compare-and-swap\">https:\/\/blogs.oracle.com\/dave\/atomic-fetch-and-add-vs-compare-and-swap<\/a><\/code><\/li><li>False sharing\uff1a<code><a rel=\"noreferrer noopener\" aria-label=\"https:\/\/en.wikipedia.org\/wiki\/False_sharing\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/en.wikipedia.org\/wiki\/False_sharing\" target=\"_blank\">https:\/\/en.wikipedia.org\/wiki\/False_sharing<\/a><\/code><\/li><li>JEP 142: Reduce Cache Contention on Specified Fields\uff1a<code><a href=\"http:\/\/openjdk.java.net\/jeps\/142\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"http:\/\/openjdk.java.net\/jeps\/142\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">http:\/\/openjdk.java.net\/jeps\/142<\/a><\/code><\/li><\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=5263\">\u9762\u8bd5\u5b98\uff1a\u4e3a\u4ec0\u4e48LongAdder\u6027\u80fd\u6bd4long\u8fd8\u5feb<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u6700\u8fd1\u4e00\u6bb5\u65f6\u95f4\u7684\u8bd5\u9a8c\uff0c\u6211\u53d1\u73b0\u5468\u516d\u5468\u65e5\u5199\u539f\u521b\uff0c\u6ca1\u591a\u5c11\u4eba\u770b\uff01 \u56e0\u6b64\uff0c\u4ee5\u540e\u5c3d\u91cf\u5c06\u5468\u516d\u5468\u65e5\u5199\u7684\u539f\u521b\u6587\u7ae0\uff0c\u653e\u5728\u5468\u4e00\u548c\u5468 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1740,710,2079,531,502],"class_list":["post-5263","post","type-post","status-publish","format-standard","hentry","category-java","tag-atomicinteger","tag-atomicreference","tag-longadder","tag-531","tag-502"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5263"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5263\/revisions"}],"predecessor-version":[{"id":5264,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5263\/revisions\/5264"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}