{"id":260851,"date":"2023-01-31T10:16:14","date_gmt":"2023-01-31T02:16:14","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=260851"},"modified":"2023-01-07T17:16:52","modified_gmt":"2023-01-07T09:16:52","slug":"stampedlock","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/stampedlock.html","title":{"rendered":"2023\u5e74\u4e00\u8d77\u6765\u8ba4\u8bc6\u4e00\u4e0bStampedLock\u5427"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86StampedLock\u200b\u7684\u529f\u80fd\u548c\u4f7f\u7528\uff0c\u81f3\u4e8e\u539f\u7406\uff0cStampedLock\u867d\u7136\u4e0d\u50cf\u5176\u5b83\u9501\u4e00\u6837\u5b9a\u4e49\u4e86\u5185\u90e8\u7c7b\u6765\u5b9e\u73b0AQS\u6846\u67b6\uff0c\u4f46\u662fStampedLock\u7684\u57fa\u672c\u5b9e\u73b0\u601d\u8def\u8fd8\u662f\u5229\u7528CLH\u961f\u5217\u8fdb\u884c\u7ebf\u7a0b\u7684\u7ba1\u7406\uff0c\u901a\u8fc7\u540c\u6b65\u72b6\u6001\u503c\u6765\u8868\u793a\u9501\u7684\u72b6\u6001\u548c\u7c7b\u578b\uff0c\u5177\u4f53\u7684\u6e90\u7801\u5b9e\u73b0\u5927\u5bb6\u611f\u5174\u8da3\u7684\u81ea\u5df1\u53ef\u4ee5\u8ffd\u8e2a\u770b\u770b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u6982\u8ff0<\/strong><\/div>\n

\u60f3\u5230\u8bfb\u5199\u9501\uff0c\u5927\u5bb6\u7b2c\u4e00\u65f6\u95f4\u60f3\u5230\u7684\u53ef\u80fd\u662fReentrantReadWriteLock\u200b\u3002\u5b9e\u9645\u4e0a\uff0c\u5728jdk8\u4ee5\u540e\uff0cjava\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6027\u80fd\u66f4\u4f18\u8d8a\u7684\u8bfb\u5199\u9501\u5e76\u53d1\u7c7bStampedLock\u200b\uff0c\u8be5\u7c7b\u7684\u8bbe\u8ba1\u521d\u8877\u662f\u4f5c\u4e3a\u4e00\u4e2a\u5185\u90e8\u5de5\u5177\u7c7b\uff0c\u7528\u4e8e\u8f85\u52a9\u5f00\u53d1\u5176\u5b83\u7ebf\u7a0b\u5b89\u5168\u7ec4\u4ef6\uff0c\u7528\u5f97\u597d\uff0c\u8be5\u7c7b\u53ef\u4ee5\u63d0\u5347\u7cfb\u7edf\u6027\u80fd\uff0c\u7528\u4e0d\u597d\uff0c\u5bb9\u6613\u4ea7\u751f\u6b7b\u9501\u548c\u5176\u5b83\u83ab\u540d\u5176\u5999\u7684\u95ee\u9898\u3002\u672c\u6587\u4e3b\u8981\u548c\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u4e0bStampedLock\u7684\u529f\u80fd\u548c\u4f7f\u7528\u3002<\/p>\n

StampedLock\u4ecb\u7ecd<\/strong><\/div>\n

StampedLock\u200b\u7684\u72b6\u6001\u7531\u7248\u672c\u548c\u6a21\u5f0f\u7ec4\u6210\u3002\u9501\u83b7\u53d6\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c\u8be5\u6233\u8868\u793a\u5e76\u63a7\u5236\u5bf9\u9501\u72b6\u6001\u7684\u8bbf\u95ee\u3002StampedLock\u63d0\u4f9b\u4e863\u79cd\u6a21\u5f0f\u63a7\u5236\u8bbf\u95ee\u9501\uff1a<\/p>\n

\u5199\u6a21\u5f0f<\/strong><\/div>\n

\u83b7\u53d6\u5199\u9501\uff0c\u5b83\u662f\u72ec\u5360\u7684\uff0c\u5f53\u9501\u5904\u4e8e\u5199\u6a21\u5f0f\u65f6\uff0c\u65e0\u6cd5\u83b7\u5f97\u8bfb\u9501\uff0c\u6240\u6709\u4e50\u89c2\u8bfb\u9a8c\u8bc1\u90fd\u5c06\u5931\u8d25\u3002<\/p>\n

  • writeLock()\uff1a \u963b\u585e\u7b49\u5f85\u72ec\u5360\u83b7\u53d6\u9501\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • tryWriteLock()\uff1a\u5c1d\u8bd5\u83b7\u53d6\u4e00\u4e2a\u5199\u9501\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • long tryWriteLock(long time, TimeUnit unit): \u5c1d\u8bd5\u83b7\u53d6\u4e00\u4e2a\u72ec\u5360\u5199\u9501\uff0c\u53ef\u4ee5\u7b49\u5f85\u4e00\u6bb5\u4e8b\u4ef6\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • long writeLockInterruptibly(): \u8bd5\u83b7\u53d6\u4e00\u4e2a\u72ec\u5360\u5199\u9501\uff0c\u53ef\u4ee5\u88ab\u4e2d\u65ad\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • unlockWrite(long stamp)\uff1a\u91ca\u653e\u72ec\u5360\u5199\u9501\uff0c\u4f20\u5165\u4e4b\u524d\u83b7\u53d6\u7684\u6233\u3002<\/li>\n
  • tryUnlockWrite()\uff1a\u5982\u679c\u6301\u6709\u5199\u9501\uff0c\u5219\u91ca\u653e\u8be5\u9501\uff0c\u800c\u4e0d\u9700\u8981\u6233\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u5bf9\u9519\u8bef\u540e\u7684\u6062\u590d\u5f88\u6709\u7528\u3002<\/li>\n
    \r\nlong stamp = lock.writeLock();\r\ntry {\r\n    ....\r\n} finally {\r\n    lock.unlockWrite(stamp);\r\n}\r\n<\/pre>\n
    \u8bfb\u6a21\u5f0f<\/strong><\/div>\n

    \u60b2\u89c2\u7684\u65b9\u5f0f\u540e\u53bb\u975e\u72ec\u5360\u8bfb\u9501\u3002<\/p>\n

  • readLock()\uff1a \u963b\u585e\u7b49\u5f85\u83b7\u53d6\u975e\u72ec\u5360\u7684\u8bfb\u9501\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • tryReadLock()\uff1a\u5c1d\u8bd5\u83b7\u53d6\u4e00\u4e2a\u8bfb\u9501\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • long tryReadLock(long time, TimeUnit unit): \u5c1d\u8bd5\u83b7\u53d6\u4e00\u4e2a\u8bfb\u9501\uff0c\u53ef\u4ee5\u7b49\u5f85\u4e00\u6bb5\u4e8b\u4ef6\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • long readLockInterruptibly(): \u963b\u585e\u7b49\u5f85\u83b7\u53d6\u975e\u72ec\u5360\u7684\u8bfb\u9501\uff0c\u53ef\u4ee5\u88ab\u4e2d\u65ad\uff0c\u8fd4\u56de\u4e00\u4e2a\u6233\uff0c \u5982\u679c\u662f0\u8868\u793a\u83b7\u53d6\u5931\u8d25\u3002<\/li>\n
  • unlockRead(long stamp)\uff1a\u91ca\u653e\u975e\u72ec\u5360\u7684\u8bfb\u9501\uff0c\u4f20\u5165\u4e4b\u524d\u83b7\u53d6\u7684\u6233\u3002<\/li>\n
  • tryUnlockRead()\uff1a\u5982\u679c\u8bfb\u9501\u88ab\u6301\u6709\uff0c\u5219\u91ca\u653e\u4e00\u6b21\u6301\u6709\uff0c\u800c\u4e0d\u9700\u8981\u6233\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u5bf9\u9519\u8bef\u540e\u7684\u6062\u590d\u5f88\u6709\u7528\u3002<\/li>\n
    \r\nlong stamp = lock.readLock();\r\ntry {\r\n    ....\r\n} finally {\r\n    lock.unlockRead(stamp);        \r\n}\r\n<\/pre>\n
    \u4e50\u89c2\u8bfb\u6a21\u5f0f<\/strong><\/div>\n

    \u4e50\u89c2\u8bfb\u4e5f\u5c31\u662f\u82e5\u8bfb\u7684\u64cd\u4f5c\u5f88\u591a\uff0c\u5199\u7684\u64cd\u4f5c\u5f88\u5c11\u7684\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4e50\u89c2\u5730\u8ba4\u4e3a\uff0c\u5199\u5165\u4e0e\u8bfb\u53d6\u540c\u65f6\u53d1\u751f\u51e0\u7387\u5f88\u5c11\uff0c\u56e0\u6b64\u4e0d\u60b2\u89c2\u5730\u4f7f\u7528\u5b8c\u5168\u7684\u8bfb\u53d6\u9501\u5b9a\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u67e5\u770b\u8bfb\u53d6\u8d44\u6599\u4e4b\u540e\uff0c\u662f\u5426\u906d\u5230\u5199\u5165\u6267\u884c\u7684\u53d8\u66f4\uff0c\u518d\u91c7\u53d6\u540e\u7eed\u7684\u63aa\u65bd(\u91cd\u65b0\u8bfb\u53d6\u53d8\u66f4\u4fe1\u606f\uff0c\u6216\u8005\u629b\u51fa\u5f02\u5e38) \uff0c\u8fd9\u4e00\u4e2a\u5c0f\u5c0f\u6539\u8fdb\uff0c\u53ef\u5927\u5e45\u5ea6\u63d0\u9ad8\u7a0b\u5e8f\u7684\u541e\u5410\u91cf\u3002<\/p>\n

    StampedLock\u200b\u652f\u6301 tryOptimisticRead()\u65b9\u6cd5\uff0c\u8bfb\u53d6\u5b8c\u6bd5\u540e\u505a\u4e00\u6b21\u6233\u6821\u9a8c\uff0c\u5982\u679c\u6821\u9a8c\u901a\u8fc7\uff0c\u8868\u793a\u8fd9\u671f\u95f4\u6ca1\u6709\u5176\u4ed6\u7ebf\u7a0b\u7684\u5199\u64cd\u4f5c\uff0c\u6570\u636e\u53ef\u4ee5\u5b89\u5168\u4f7f\u7528\uff0c\u5982\u679c\u6821\u9a8c\u6ca1\u901a\u8fc7\uff0c\u9700\u8981\u91cd\u65b0\u83b7\u53d6\u8bfb\u9501\uff0c\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u3002<\/p>\n

  • tryOptimisticRead(): \u8fd4\u56de\u7a0d\u540e\u53ef\u4ee5\u9a8c\u8bc1\u7684\u6233\u8bb0\uff0c\u5982\u679c\u72ec\u5360\u9501\u5b9a\u5219\u8fd4\u56de\u96f6\u3002<\/li>\n
  • boolean validate(long stamp): \u5982\u679c\u81ea\u7ed9\u5b9a\u6233\u8bb0\u53d1\u884c\u4ee5\u6765\u9501\u8fd8\u6ca1\u6709\u88ab\u72ec\u5360\u83b7\u53d6\uff0c\u5219\u8fd4\u56detrue\u3002<\/li>\n
    \r\nlong stamp = lock.tryOptimisticRead();\r\n\/\/ \u9a8c\u6233\r\nif(!lock.validate(stamp)){\r\n  \/\/ \u9501\u5347\u7ea7\r\n}\r\n<\/pre>\n

    \u6b64\u5916\uff0cStampedLock \u63d0\u4f9b\u4e86api\u5b9e\u73b0\u4e0a\u97623\u79cd\u65b9\u5f0f\u8fdb\u884c\u8f6c\u6362\uff1a<\/p>\n

  • long tryConvertToWriteLock(long stamp)<\/li>\n

    \u5982\u679c\u9501\u72b6\u6001\u4e0e\u7ed9\u5b9a\u7684\u6233\u8bb0\u5339\u914d\uff0c\u5219\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u4e4b\u4e00\u3002\u5982\u679c\u6233\u8bb0\u8868\u793a\u6301\u6709\u5199\u9501\uff0c\u5219\u8fd4\u56de\u5b83\u3002\u6216\u8005\uff0c\u5982\u679c\u662f\u8bfb\u9501\uff0c\u5982\u679c\u5199\u9501\u53ef\u7528\uff0c\u5219\u91ca\u653e\u8bfb\u9501\u5e76\u8fd4\u56de\u5199\u6233\u8bb0\u3002\u6216\u8005\uff0c\u5982\u679c\u662f\u4e50\u89c2\u8bfb\uff0c\u5219\u4ec5\u5728\u7acb\u5373\u53ef\u7528\u65f6\u8fd4\u56de\u5199\u6233\u8bb0\u3002\u8be5\u65b9\u6cd5\u5728\u6240\u6709\u5176\u4ed6\u60c5\u51b5\u4e0b\u8fd4\u56de\u96f6<\/p>\n

  • long tryConvertToReadLock(long stamp)<\/li>\n

    \u5982\u679c\u9501\u72b6\u6001\u4e0e\u7ed9\u5b9a\u7684\u6233\u8bb0\u5339\u914d\uff0c\u5219\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u4e4b\u4e00\u3002\u5982\u679c\u6233\u8bb0\u8868\u793a\u6301\u6709\u5199\u9501\uff0c\u5219\u91ca\u653e\u5b83\u5e76\u83b7\u5f97\u8bfb\u9501\u3002\u6216\u8005\uff0c\u5982\u679c\u662f\u8bfb\u9501\uff0c\u8fd4\u56de\u5b83\u3002\u6216\u8005\uff0c\u5982\u679c\u662f\u4e50\u89c2\u8bfb\uff0c\u5219\u4ec5\u5728\u7acb\u5373\u53ef\u7528\u65f6\u624d\u83b7\u5f97\u8bfb\u9501\u5e76\u8fd4\u56de\u8bfb\u6233\u8bb0\u3002\u8be5\u65b9\u6cd5\u5728\u6240\u6709\u5176\u4ed6\u60c5\u51b5\u4e0b\u8fd4\u56de\u96f6\u3002<\/p>\n

  • long tryConvertToOptimisticRead(long stamp)<\/li>\n

    \u5982\u679c\u9501\u72b6\u6001\u4e0e\u7ed9\u5b9a\u7684\u6233\u8bb0\u5339\u914d\uff0c\u90a3\u4e48\u5982\u679c\u6233\u8bb0\u8868\u793a\u6301\u6709\u9501\uff0c\u5219\u91ca\u653e\u5b83\u5e76\u8fd4\u56de\u4e00\u4e2a\u89c2\u5bdf\u6233\u8bb0\u3002\u6216\u8005\uff0c\u5982\u679c\u662f\u4e50\u89c2\u8bfb\uff0c\u5219\u5728\u9a8c\u8bc1\u540e\u8fd4\u56de\u5b83\u3002\u8be5\u65b9\u6cd5\u5728\u6240\u6709\u5176\u4ed6\u60c5\u51b5\u4e0b\u8fd4\u56de0\uff0c\u56e0\u6b64\u4f5c\u4e3a\u201ctryUnlock\u201d\u7684\u5f62\u5f0f\u53ef\u80fd\u5f88\u6709\u7528\u3002<\/p>\n

    \u6f14\u793a\u4f8b\u5b50<\/strong><\/div>\n

    \u4e0b\u9762\u7528\u4e00\u4e2a\u4f8b\u5b50\u6f14\u793a\u4e0bStampedLock\u7684\u4f7f\u7528\uff0c\u4f8b\u5b50\u6765\u6e90jdk\u4e2d\u7684javadoc\u3002<\/p>\n

    \r\n@Slf4j\r\n@Data\r\npublic class Point {\r\n    private double x, y;\r\n    private final StampedLock sl = new StampedLock();\r\n\r\n    void move(double deltaX, double throws{\r\n        \/\/\u6d89\u53ca\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u4fee\u6539\uff0c\u4f7f\u7528\u5199\u9501-\u72ec\u5360\u64cd\u4f5c\r\n        long stamp = sl.writeLock();\r\n        log.info(\"writeLock lock success\");\r\n        Thread.sleep(500);\r\n        try {\r\n            x += deltaX;\r\n            y += deltaY;\r\n        } finally {\r\n            sl.unlockWrite(stamp);\r\n            log.info(\"unlock write lock success\");\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * \u4f7f\u7528\u4e50\u89c2\u8bfb\u9501\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\r\n     * \u6ce8\u610f\uff1a\u4e50\u89c2\u8bfb\u9501\u5728\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u4e0a\u9700\u8981\u62f7\u8d1d\u4e00\u4efd\u8981\u64cd\u4f5c\u7684\u53d8\u91cf\u5230\u65b9\u6cd5\u6808\uff0c\u5e76\u4e14\u5728\u64cd\u4f5c\u6570\u636e\u65f6\u5019\u53ef\u80fd\u5176\u4ed6\u5199\u7ebf\u7a0b\u5df2\u7ecf\u4fee\u6539\u4e86\u6570\u636e\uff0c\r\n     * \u800c\u6211\u4eec\u64cd\u4f5c\u7684\u662f\u65b9\u6cd5\u6808\u91cc\u9762\u7684\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u5feb\u7167\uff0c\u6240\u4ee5\u6700\u591a\u8fd4\u56de\u7684\u4e0d\u662f\u6700\u65b0\u7684\u6570\u636e\uff0c\u4f46\u662f\u4e00\u81f4\u6027\u8fd8\u662f\u5f97\u5230\u4fdd\u969c\u7684\u3002\r\n     *\r\n     * @return\r\n     *\/\r\n    double distanceFromOrigin() throws{\r\n        long stamp = sl.tryOptimisticRead();    \/\/ \u4f7f\u7528\u4e50\u89c2\u8bfb\u9501\r\n        log.info(\"tryOptimisticRead lock success\");\r\n        \/\/ \u7761\u4e00\u79d2\u4e2d\r\n        Thread.sleep(1000);\r\n        double currentX = x, currentY = y;      \/\/ \u62f7\u8d1d\u5171\u4eab\u8d44\u6e90\u5230\u672c\u5730\u65b9\u6cd5\u6808\u4e2d\r\n        if (!sl.validate(stamp)) {              \/\/ \u5982\u679c\u6709\u5199\u9501\u88ab\u5360\u7528\uff0c\u53ef\u80fd\u9020\u6210\u6570\u636e\u4e0d\u4e00\u81f4\uff0c\u6240\u4ee5\u8981\u5207\u6362\u5230\u666e\u901a\u8bfb\u9501\u6a21\u5f0f\r\n            log.info(\"validate stamp error\");\r\n            stamp = sl.readLock();\r\n            log.info(\"readLock success\");\r\n            try {\r\n                currentX = x;\r\n                currentY = y;\r\n            } finally {\r\n                sl.unlockRead(stamp);\r\n                log.info(\"unlock read success\");\r\n            }\r\n        }\r\n        return Math.sqrt(currentX * currentX + currentY * currentY);\r\n    }\r\n\r\n    void moveIfAtOrigin(double newX, double{ \/\/ upgrade\r\n        \/\/ Could instead start with optimistic, not read mode\r\n        long stamp = sl.readLock();\r\n        try {\r\n            while (x == 0.0 && y == 0.0) {\r\n                long ws = sl.tryConvertToWriteLock(stamp);  \/\/\u8bfb\u9501\u8f6c\u6362\u4e3a\u5199\u9501\r\n                if (ws != 0L) {\r\n                    stamp = ws;\r\n                    x = newX;\r\n                    y = newY;\r\n                    break;\r\n                } else {\r\n                    sl.unlockRead(stamp);\r\n                    stamp = sl.writeLock();\r\n                }\r\n            }\r\n        } finally {\r\n            sl.unlock(stamp);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n

    \u6d4b\u8bd5\u7528\u4f8b\uff1a<\/p>\n

    \r\n@Test\r\npublic void testStamped() throws InterruptedException {\r\n    Point point = new Point();\r\n    point.setX(1);\r\n    point.setY(2);\r\n    \/\/ \u7ebf\u7a0b0 \u6267\u884c\u4e86\u4e50\u89c2\u8bfb\r\n    Thread thread0 = new Thread(() -> {\r\n        try {\r\n            \/\/ \u4e50\u89c2\u8bfb\r\n            point.distanceFromOrigin();\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }, \"thread-0\");\r\n    thread0.start();\r\n\r\n    Thread.sleep(500);\r\n    \/\/ \u7ebf\u7a0b1 \u6267\u884c\u5199\u9501\r\n    Thread thread1 = new Thread(() -> {\r\n        \/\/ \u4e50\u89c2\u8bfb\r\n        try {\r\n            point.move(3, 4);\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }, \"thread-1\");\r\n    thread1.start();\r\n\r\n    thread0.join();\r\n    thread1.join();\r\n}\r\n<\/pre>\n

    \u7ed3\u679c\uff1a<\/p>\n

    \"\"<\/p>\n

    \u6027\u80fd\u5bf9\u6bd4
    \n\u6b63\u662f\u7531\u4e8eStampedLock\u200b\u7684\u4e50\u89c2\u8bfb\u6a21\u5f0f\uff0c\u65e9\u5c31StampedLock\u7684\u9ad8\u6027\u80fd\u548c\u9ad8\u541e\u5410\u91cf\uff0c\u90a3\u4e48\u5177\u4f53\u7684\u6027\u80fd\u63d0\u9ad8\u6709\u591a\u5c11\u5462\uff1f<\/p>\n

    \u4e0b\u56fe\u662f\u548cReadWritLock\u76f8\u6bd4\uff0c\u5728\u4e00\u4e2a\u7ebf\u7a0b\u60c5\u51b5\u4e0b\uff0c\u8bfb\u901f\u5ea6\u662f\u51764\u500d\u5de6\u53f3\uff0c\u5199\u662f1\u500d\u3002<\/p>\n

    \"\"<\/p>\n

    \u4e0b\u56fe\u662f16\u4e2a\u7ebf\u7a0b\u60c5\u51b5\u4e0b\uff0c\u8bfb\u6027\u80fd\u662f\u5176\u51e0\u5341\u500d\uff0c\u5199\u6027\u80fd\u4e5f\u662f\u8fd110\u500d\u5de6\u53f3\uff1a<\/p>\n

    \"\"<\/p>\n

    \u4e0b\u56fe\u662f\u541e\u5410\u91cf\u63d0\u9ad8\uff1a<\/p>\n

    \"\"<\/p>\n

    \u90a3\u4e48\u8fd9\u6837\u662f\u4e0d\u662f\u8bf4StampedLock\u200b\u53ef\u4ee5\u5168\u65b9\u4f4d\u7684\u66ff\u4ee3ReentrantReadWriteLock\u200b, \u7b54\u6848\u662f\u5426\u5b9a\u7684\uff0cStampedLock\u200b\u76f8\u5bf9\u4e8eReentrantReadWriteLock\u6709\u4e0b\u9762\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n

  • \u4e0d\u652f\u6301\u6761\u4ef6\u53d8\u91cfCondition<\/li>\n
  • \u4e0d\u652f\u6301\u53ef\u91cd\u5165<\/li>\n

    \u6240\u4ee5\u6700\u7ec8\u9009\u62e9StampedLock\u200b\u8fd8\u662fReentrantReadWriteLock\uff0c\u8fd8\u662f\u8981\u770b\u5177\u4f53\u7684\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86StampedLock\u200b\u7684\u529f\u80fd\u548c\u4f7f\u7528\uff0c\u81f3\u4e8e\u539f\u7406\uff0cStampedLock\u867d\u7136\u4e0d\u50cf\u5176\u5b83\u9501\u4e00\u6837\u5b9a\u4e49\u4e86\u5185\u90e8\u7c7b\u6765\u5b9e\u73b0AQS\u6846\u67b6\uff0c\u4f46\u662fStampedLock\u7684\u57fa\u672c\u5b9e\u73b0\u601d\u8def\u8fd8\u662f\u5229\u7528CLH\u961f\u5217\u8fdb\u884c\u7ebf\u7a0b\u7684\u7ba1\u7406\uff0c\u901a\u8fc7\u540c\u6b65\u72b6\u6001\u503c\u6765\u8868\u793a\u9501\u7684\u72b6\u6001\u548c\u7c7b\u578b\uff0c\u5177\u4f53\u7684\u6e90\u7801\u5b9e\u73b0\u5927\u5bb6\u611f\u5174\u8da3\u7684\u81ea\u5df1\u53ef\u4ee5\u8ffd\u8e2a\u770b\u770b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u60f3\u5230\u8bfb\u5199\u9501\uff0c\u5927\u5bb6\u7b2c\u4e00\u65f6\u95f4\u60f3\u5230\u7684\u53ef\u80fd\u662fReentrantReadWriteLock\u200b\u3002\u5b9e\u9645\u4e0a\uff0c\u5728jdk8\u4ee5\u540e\uff0cj […]<\/p>\n","protected":false},"author":1898,"featured_media":260859,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[974],"class_list":["post-260851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-stampedlock"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/260851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=260851"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/260851\/revisions"}],"predecessor-version":[{"id":260861,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/260851\/revisions\/260861"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/260859"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=260851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=260851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=260851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}