{"id":1053,"date":"2024-11-30T13:56:16","date_gmt":"2024-11-30T05:56:16","guid":{"rendered":"https:\/\/www.coffecat.cn\/?p=1053"},"modified":"2024-11-30T13:58:56","modified_gmt":"2024-11-30T05:58:56","slug":"%e3%80%90%e5%9c%ba%e6%99%af%e5%ba%94%e7%94%a8%e8%ae%b0%e5%bd%95%e3%80%91-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%90%91mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e5%bf%ab%e9%80%9f%e6%8f%92%e5%85%a5100w","status":"publish","type":"post","link":"https:\/\/www.coffecat.cn\/index.php\/2024\/11\/30\/%e3%80%90%e5%9c%ba%e6%99%af%e5%ba%94%e7%94%a8%e8%ae%b0%e5%bd%95%e3%80%91-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%90%91mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e5%bf%ab%e9%80%9f%e6%8f%92%e5%85%a5100w\/","title":{"rendered":"\u3010\u573a\u666f\u5e94\u7528\u8bb0\u5f55\u3011- \u5982\u4f55\u5b9e\u73b0\u5411mysql\u6570\u636e\u5e93\u4e2d\u5feb\u901f\u63d2\u5165100w\u6761\u6570\u636e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u9996\u5148\u5148\u8bf4\u7ed3\u8bba\uff1a\u591a\u7ebf\u7a0b&gt;\u5355\u7ebf\u7a0b\uff0c\u6279\u91cf\u63d2\u5165&gt;\u5355\u72ec\u63d2\u5165<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u5411\u6570\u636e\u5e93\u4e2d\u63d2\u5165\u6570\u636e\uff1f\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u6bd4\u5982\uff1a\u7f16\u5199sql\u8bed\u53e5\uff0c\u4f7f\u7528\u5de5\u5177\u5bfc\u5165\uff08poi\uff0ceasy excel\uff09,\u5185\u5b58\u8ba1\u7b97\u5904\u7406\uff0c\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u5de5\u5177\u4ece\u5176\u4ed6\u5e93\u4e2d\u5bfc\u5165\uff08\u76f8\u540c\u7c7b\u578b\u6570\u636e\u5e93\uff0c\u76f8\u540c\u7684\u8868\uff09\u7b49\u7b49<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u5411\u6570\u636e\u5e93\u4e2d\u5feb\u901f\u63d2\u5165\u6570\u636e\uff1f \u5f53\u6570\u636e\u6bd4\u8f83\u591a\u65f6\u6bcf\u6761\u6570\u636e\u5355\u72ec\u63d2\u5165\u5c31\u4e0d\u592a\u9002\u7528\u4e86\uff0c\u56e0\u4e3a\u6bcf\u6761\u6570\u636e\u90fd\u4f1a\u5360\u7528\u6570\u636e\u5e93\u7684\u4e00\u4e2a\u8fde\u63a5\uff0c\u5f53\u6570\u636e\u5e93\u8fde\u63a5\u6ee1\u4e86\u540e\u5176\u4ed6\u5e94\u7528\u6216\u8005\u670d\u52a1\u5c31\u65e0\u6cd5\u4f7f\u7528\u6570\u636e\u5e93\u4e86\uff0c\u53ea\u80fd\u7b49\u5f85\u6709\u7a7a\u4f59\u7684\u8fde\u63a5\u65f6\u624d\u80fd\u7ee7\u7eed\u8bbf\u95ee\u5e76\u4e14\u5bf9\u4e8e\u6570\u636e\u5e93\u7684\u538b\u529b\u4e5f\u662f\u5f88\u5927\u7684\uff08\u540c\u65f6\u4e5f\u548c\u6570\u636e\u5e93\u7684\u786c\u4ef6\u914d\u7f6e\u6709\u5173\uff09\u3002\u8fd9\u4e2a\u65f6\u5019\u6279\u91cf\u63d2\u5165\u5c31\u5f88\u6709\u4f18\u52bf\uff0cmybatisplus\u63d0\u4f9b\u4e86\u4e00\u5957\u65b9\u6cd5\u53ef\u4ee5\u6279\u91cf\u64cd\u4f5c\u6570\u636e\uff0c\u4f8b\u5982\uff1asaveBatch\u65b9\u6cd5\uff0c\u9ed8\u8ba4\u4e00\u6279\u53ef\u4ee5\u5b58\u653e1000\u6761\u6570\u636e\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5b9a\u4e49\u5b58\u653e\u6761\u6570<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"    default boolean saveBatch(Collection&lt;T&gt; entityList) {\n        return this.saveBatch(entityList, 10000);\n    }\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">default<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">boolean<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">saveBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #8FBCBB\">Collection<\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">T<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> entityList<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">this<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">saveBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">entityList<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">10000<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u5728\u6d4b\u8bd5\u6279\u91cf\u63d2\u5165\u6570\u636e\u65f6\u901f\u5ea6\u5e76\u4e0d\u5feb\uff0c\u6839\u636e\u5b9e\u73b0\u7684\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u65b9\u6cd5\u5185\u4f1a\u5c06\u83b7\u53d6\u5230\u7684\u6570\u636e\u96c6\u5408\u5206\u6279\u6267\u884c\u63d2\u5165\u64cd\u4f5c\uff0c\u6bcf\u6279\u6570\u91cf\u7531batchSize\u63a7\u5236\uff0c\u5728\u6bcf\u4e2a\u6279\u6b21\u4e2d\uff0c<code>saveBatch<\/code>\u00a0\u65b9\u6cd5\u4f1a\u9010\u4e2a\u63d2\u5165\u5b9e\u4f53\u5bf9\u8c61\uff08\u8c03\u7528ibatis\u7684<code>sqlSession.insert(sqlStatement, entity)<\/code>\u65b9\u6cd5\uff09<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"    public boolean saveBatch(Collection&lt;T&gt; entityList, int batchSize) {\n        String sqlStatement = this.getSqlStatement(SqlMethod.INSERT_ONE);\n        return this.executeBatch(entityList, batchSize, (sqlSession, entity) -&gt; sqlSession.insert(sqlStatement, entity));\n    }\n\n    protected String getSqlStatement(SqlMethod sqlMethod) {\n        return SqlHelper.getSqlStatement(this.mapperClass, sqlMethod);\n    }\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">boolean<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">saveBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #8FBCBB\">Collection<\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">T<\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> entityList<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> batchSize<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">String<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">sqlStatement<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">this<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getSqlStatement<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">SqlMethod<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">INSERT_ONE<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">this<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">executeBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">entityList<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> batchSize<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">sqlSession<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> entity<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">-&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">sqlSession<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">insert<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">sqlStatement<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> entity<\/span><span style=\"color: #ECEFF4\">))<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">protected<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">String<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">getSqlStatement<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #8FBCBB\">SqlMethod<\/span><span style=\"color: #D8DEE9FF\"> sqlMethod<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">SqlHelper<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getSqlStatement<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">this<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">mapperClass<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> sqlMethod<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u501f\u52a9csdn\u535a\u4e3b<a href=\"https:\/\/blog.csdn.net\/m0_70871140\" target=\"_blank\" rel=\"noreferrer noopener\">\u603b\u662f\u5b66\u4e0d\u4f1a.<\/a>\u7684\u4e00\u4e9b\u89c2\u70b9\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f18\u52bf<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b80\u4fbf\u6613\u7528<\/strong>\uff1a\u65e0\u9700\u624b\u52a8\u7f16\u5199 SQL\uff0c\u76f4\u63a5\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u5373\u53ef\u3002<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u4e8b\u52a1\u7ba1\u7406<\/strong>\uff1a\u5185\u7f6e\u4e8b\u52a1\u652f\u6301\uff0c\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><a><\/a><a><\/a>\u7f3a\u70b9<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6027\u80fd\u6709\u9650<\/strong>\uff1a\u5e95\u5c42\u9010\u6761\u63d2\u5165\uff0c\u9762\u5bf9\u5927\u6570\u636e\u91cf\u65f6\u6548\u7387\u8f83\u4f4e\u3002<\/li>\n\n\n\n<li><strong>\u6279\u91cf\u5927\u5c0f\u53d7\u9650<\/strong>\uff1a\u9ed8\u8ba4\u6279\u91cf\u5927\u5c0f\u53ef\u80fd\u4e0d\u9002\u7528\u4e8e\u6240\u6709\u573a\u666f\uff0c\u9700\u8981\u624b\u52a8\u8c03\u6574\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u5e76\u4e0d\u662f\u8bf4\u65e0\u6cd5\u4f18\u5316\uff0c\u5728csdn\u535a\u4e3b<a href=\"https:\/\/blog.csdn.net\/m0_70871140\" target=\"_blank\" rel=\"noreferrer noopener\">\u603b\u662f\u5b66\u4e0d\u4f1a.<\/a>\u7684\u6587\u7ae0\u4e2d\u6709\u6240\u8bf4\u660e\u4f18\u5316\u529e\u6cd5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.<strong>\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570<\/strong>\uff08\u6ce8\u610f\uff1a\u5982\u679c\u4f60\u7684\u94fe\u63a5\u4e2d\u5df2\u7ecf\u914d\u7f6e\u4e86\u5176\u4ed6\u53c2\u6570\uff0c\u6ce8\u610f\u53c2\u6570\u4e0e\u53c2\u6570\u4e4b\u95f4\u4f7f\u7528&amp;\u7b26\u8fdb\u884c\u8fde\u63a5\uff09<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"spring.datasource.url=jdbc:mysql:\/\/localhost:3306\/your_database?rewriteBatchedStatements=true\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">spring.datasource.url=jdbc:mysql:\/\/localhost:3306\/your_database?rewriteBatchedStatements=true<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><code>rewriteBatchedStatements=true<\/code>&nbsp;\u662f MySQL JDBC \u9a71\u52a8\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u53c2\u6570\uff0c\u7528\u4e8e\u4f18\u5316\u6279\u91cf\u63d2\u5165\uff08Batch Insert\uff09\u64cd\u4f5c\u7684\u6027\u80fd\u5f53&nbsp;<code>rewriteBatchedStatements=true<\/code>&nbsp;\u65f6\uff0cJDBC \u9a71\u52a8\u4f1a\u91cd\u5199\u6279\u91cf\u63d2\u5165\u8bed\u53e5\uff0c\u5c06\u591a\u4e2a&nbsp;<code>INSERT<\/code>&nbsp;\u8bed\u53e5\u5408\u5e76\u5230\u4e00\u4e2a SQL \u8bed\u53e5\u4e2d\u6267\u884c\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u4e0e\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u901a\u4fe1\u6b21\u6570\uff0c\u4ece\u800c\u63d0\u9ad8\u63d2\u5165\u6027\u80fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u6765\u8bf4\uff0c\u9a71\u52a8\u4f1a\u5c06\u591a\u4e2a\u63d2\u5165\u8bed\u53e5\u5408\u5e76\u6210\u4e00\u6761&nbsp;<code>INSERT INTO table_name (column1, column2) VALUES (value1, value2), (value3, value4), ...<\/code>&nbsp;\u8bed\u53e5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u517c\u5bb9\u6027<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u786e\u4fdd\u4f7f\u7528\u7684\u662f MySQL  5.1.13 \u6216\u66f4\u9ad8\u7248\u672c\uff0c\u56e0\u4e3a\u5728\u6b64\u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u8be5\u53c2\u6570\u53ef\u80fd\u4e0d\u4f1a\u751f\u6548\u6216\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e8b\u52a1\u5904\u7406<\/strong>: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u5982\u679c\u5728\u4e8b\u52a1\u4e2d\u8fdb\u884c\u6279\u91cf\u63d2\u5165\uff0c\u786e\u4fdd&nbsp;<code>rewriteBatchedStatements=true<\/code>&nbsp;\u4e0d\u4f1a\u5f71\u54cd\u4e8b\u52a1\u7684\u4e00\u81f4\u6027\u548c\u9694\u79bb\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u8d34\u51facsdn\u535a\u4e3b<a href=\"https:\/\/blog.csdn.net\/m0_70871140\" target=\"_blank\" rel=\"noreferrer noopener\">\u603b\u662f\u5b66\u4e0d\u4f1a.<\/a>\u7684\u6587\u7ae0\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u8003\uff0c\u5bf9\u4e8eMybatisPlus\u6279\u91cf\u63d2\u5165\u4e0e\u4f18\u5316\u8bb2\u89e3\u7684\u975e\u5e38\u8be6\u7ec6<a href=\"https:\/\/blog.csdn.net\/m0_70871140\/article\/details\/142731767\">https:\/\/blog.csdn.net\/m0_70871140\/article\/details\/142731767<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u6b64\u4ee5\u5916\u5f53\u6570\u636e\u91cf\u66f4\u52a0\u5e9e\u5927\u65f6\u8fd9\u79cd\u4e32\u884c\u6267\u884c\u7684\u65b9\u5f0f\u5c31\u4e0d\u518d\u9002\u7528\u4e86\uff0c \u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u591a\u7ebf\u7a0b\u7684\u65b9\u5f0f\u5728\u6279\u91cf\u63d2\u5165\u7684\u57fa\u7840\u4e0a\u5e76\u884c\u6267\u884c\u63d2\u5165\u64cd\u4f5c\u63d0\u5347\u6267\u884c\u6548\u7387\u3002\u8fd9\u91cc\u5148\u8d34\u51fa\u4ee3\u7801\uff0c\u540e\u9762\u518d\u4e00\u6b65\u4e00\u6b65\u8fdb\u884c\u8bb2\u89e3<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"    \/**\n     * \u63d2\u5165\u6570\u636e \u591a\u7ebf\u7a0b\u6267\u884c\n     *\/\n    @Test\n    void concurrencyInsertUsers() {\n        \/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\n        StopWatch stopWatch = new StopWatch();\n        \/\/\u5f00\u59cb\u8bb0\u5f55\u65f6\u95f4\n        stopWatch.start();\n        \/\/\u6bcf\u6279\u63d2\u516550000\u6761\u6570\u636e\n        final int batch_insert = 50000;\n        \/\/\u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\u5217\u8868\n        List&lt;CompletableFuture&lt;Void&gt;&gt; futures = new ArrayList&lt;&gt;();\n        \/\/\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\n        ThreadPoolExecutor threadPoolExecutor =\n                new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors()*2,\n                        80,\n                        10000,\n                        TimeUnit.MINUTES,\n                        new ArrayBlockingQueue&lt;&gt;(1000));\n        \/\/\u5faa\u73af\u63d2\u5165\u6570\u636e\n        int j = 0;\n        for (int i = 0; i &lt;20; i++) {\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u7528\u6237\u5217\u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u6279\u7528\u6237\u6570\u636e\n            ArrayList&lt;User&gt; userList = new ArrayList&lt;&gt;();\n            do {\n                j++;\n                User user = getUser(j);\n                userList.add(user);\n            } while (j % batch_insert != 0);\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230futures\u5217\u8868\u4e2d\uff0c\u4e3a\u4efb\u52a1\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\n            CompletableFuture&lt;Void&gt; future = CompletableFuture.runAsync(() -&gt; {\n                System.out.println(&quot;\u7ebf\u7a0b&quot;+Thread.currentThread().getName()+&quot;\u6267\u884c&quot;);\n                userService.saveBatch(userList, 10000);\n                userList.clear();\n            }, threadPoolExecutor);\n            \/\/ \u5c06\u5f02\u6b65\u4efb\u52a1\u52a0\u5165\u5230futures\u5217\u8868\u4e2d\n            futures.add(future);\n        }\n        \/\/ \u6267\u884c\u6240\u6709\u5f02\u6b65\u4efb\u52a1\n        CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join();\n        \/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\n        stopWatch.stop();\n        System.out.println(&quot;\u6267\u884c\u6700\u7ec8\u7528\u65f6:&quot;+stopWatch.getTotalTimeMillis());\n\n    }\n\n    private static User getUser(int i) {\n        User user = new User();\n        user.setUserPassword(&quot;5d71a8404f4c47a213b11f2b178b4eb5&quot;);\n        user.setUserCode(&quot;test&quot;+ i);\n        user.setUserName(&quot;\u6d4b\u8bd5&quot;+ i);\n        user.setUserEmail(&quot;test@qq.com&quot;);\n        user.setUserPhone(&quot;13800138000&quot;);\n        user.setUserSex(1);\n        user.setUserAvatarUrl(&quot;https:\/\/example.com\/avatar&quot;);\n        user.setRemark(&quot;test&quot;);\n        user.setUserStatus(&quot;1&quot;);\n        user.setIsDelete(0);\n        user.setCreateTime(new Date());\n        user.setUpdateTime(new Date());\n        user.setTags(&quot;&quot;);\n        return user;\n    }\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\">    \/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * \u63d2\u5165\u6570\u636e \u591a\u7ebf\u7a0b\u6267\u884c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">@<\/span><span style=\"color: #D08770\">Test<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">concurrencyInsertUsers<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">StopWatch<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">StopWatch<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u5f00\u59cb\u8bb0\u5f55\u65f6\u95f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">start<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u6bcf\u6279\u63d2\u516550000\u6761\u6570\u636e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">final<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">batch_insert<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">50000<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">List<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">Void<\/span><span style=\"color: #ECEFF4\">&gt;&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;&gt;()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">ThreadPoolExecutor<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">threadPoolExecutor<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">ThreadPoolExecutor<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">Runtime<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getRuntime<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">availableProcessors<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #B48EAD\">80<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #B48EAD\">10000<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #D8DEE9\">TimeUnit<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">MINUTES<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayBlockingQueue<\/span><span style=\"color: #ECEFF4\">&lt;&gt;(<\/span><span style=\"color: #B48EAD\">1000<\/span><span style=\"color: #ECEFF4\">))<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u5faa\u73af\u63d2\u5165\u6570\u636e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">j<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #B48EAD\">20<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> i<\/span><span style=\"color: #81A1C1\">++<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u521b\u5efa\u4e00\u4e2a\u7528\u6237\u5217\u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u6279\u7528\u6237\u6570\u636e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #ECEFF4\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;&gt;()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">do<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                j<\/span><span style=\"color: #81A1C1\">++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">getUser<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">j<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">add<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">while<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">j <\/span><span style=\"color: #81A1C1\">%<\/span><span style=\"color: #D8DEE9FF\"> batch_insert <\/span><span style=\"color: #81A1C1\">!=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230futures\u5217\u8868\u4e2d\uff0c\u4e3a\u4efb\u52a1\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">Void<\/span><span style=\"color: #ECEFF4\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">future<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">runAsync<\/span><span style=\"color: #ECEFF4\">(()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">-&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">System<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">out<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">println<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u7ebf\u7a0b<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9\">Thread<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">currentThread<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">getName<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u6267\u884c<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userService<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">saveBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">userList<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">10000<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">clear<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #ECEFF4\">},<\/span><span style=\"color: #D8DEE9FF\"> threadPoolExecutor<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u5c06\u5f02\u6b65\u4efb\u52a1\u52a0\u5165\u5230futures\u5217\u8868\u4e2d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">add<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">future<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/ \u6267\u884c\u6240\u6709\u5f02\u6b65\u4efb\u52a1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">allOf<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">toArray<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">[]{})).<\/span><span style=\"color: #88C0D0\">join<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">stop<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">System<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">out<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">println<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u6267\u884c\u6700\u7ec8\u7528\u65f6:<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getTotalTimeMillis<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">static<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">getUser<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> i<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">User<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserPassword<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">5d71a8404f4c47a213b11f2b178b4eb5<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserCode<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">test<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> i<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserName<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u6d4b\u8bd5<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> i<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserEmail<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">test@qq.com<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserPhone<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">13800138000<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserSex<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserAvatarUrl<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">https:\/\/example.com\/avatar<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setRemark<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">test<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUserStatus<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">1<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setIsDelete<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setCreateTime<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Date<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setUpdateTime<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Date<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setTags<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> user<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u6765\u8bf4\u4e00\u4e0b\u4ec0\u4e48\u662f\u591a\u7ebf\u7a0b\uff1f\u5b83\u7684\u6d41\u8f6c\u8fc7\u7a0b\u662f\u4ec0\u4e48\u6837\u5b50\u7684\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u751f\u547d\u5468\u671f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"656\" src=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-4-1024x656.png\" alt=\"\" class=\"wp-image-1074\" srcset=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-4-1024x656.png 1024w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-4-300x192.png 300w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-4-768x492.png 768w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-4.png 1440w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u65b0\u5efa\uff08new Thread\uff09<\/strong>\u5f53\u521b\u5efaThread\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff08\u5bf9\u8c61\uff09\u65f6\uff0c\u6b64\u7ebf\u7a0b\u8fdb\u5165\u65b0\u5efa\u72b6\u6001\uff08\u672a\u88ab\u542f\u52a8\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5c31\u7eea\uff08runnable\uff09<\/strong>\u7ebf\u7a0b\u5df2\u7ecf\u88ab\u542f\u52a8\uff0c\u6b63\u5728\u7b49\u5f85\u88ab\u5206\u914d\u7ed9 CPU \u65f6\u95f4\u7247\uff0c\u4e5f\u5c31\u662f\u8bf4\u6b64\u65f6\u7ebf\u7a0b\u6b63\u5728\u5c31\u7eea\u961f\u5217\u4e2d\u6392\u961f\u7b49\u5019\u5f97\u5230 CPU \u8d44\u6e90\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8fd0\u884c\uff08running\uff09<\/strong>\u7ebf\u7a0b\u83b7\u5f97 CPU \u8d44\u6e90\u6b63\u5728\u6267\u884c\u4efb\u52a1\uff08 run() \u65b9\u6cd5\uff09\uff0c\u6b64\u65f6\u9664\u975e\u6b64\u7ebf\u7a0b\u81ea\u52a8\u653e\u5f03 CPU \u8d44\u6e90\u6216\u8005\u6709\u4f18\u5148\u7ea7\u66f4\u9ad8\u7684\u7ebf\u7a0b\u8fdb\u5165\uff0c\u7ebf\u7a0b\u5c06\u4e00\u76f4\u8fd0\u884c\u5230\u7ed3\u675f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5835\u585e\uff08blocked\uff09<\/strong>\u7531\u4e8e\u67d0\u79cd\u539f\u56e0\u5bfc\u81f4\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u8ba9\u51faCPU\u5e76\u6682\u505c\u81ea\u5df1\u7684\u6267\u884c\uff0c\u5373\u8fdb\u5165\u5835\u585e\u72b6\u6001\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6b7b\u4ea1\uff08dead\uff09<\/strong>\u5f53\u7ebf\u7a0b\u6267\u884c\u5b8c\u6bd5\u6216\u88ab\u5176\u5b83\u7ebf\u7a0b\u6740\u6b7b\uff0c\u7ebf\u7a0b\u5c31\u8fdb\u5165\u6b7b\u4ea1\u72b6\u6001\uff0c\u8fd9\u65f6\u7ebf\u7a0b\u4e0d\u53ef\u80fd\u518d\u8fdb\u5165\u5c31\u7eea\u72b6\u6001\u7b49\u5f85\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5982\u679c\u8fd0\u884c\u5f88\u987a\u5229\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u7ecf\u8fc7\u65b0\u5efa->\u5c31\u7eea->\u8fd0\u884c->\u6b7b\u4ea1\u8fd9\u51e0\u79cd\u72b6\u6001\uff0c\u4f46\u662f\u5f53\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7531\u4e8e\u67d0\u79cd\u539f\u56e0\u5bfc\u81f4\u7ebf\u7a0b\u8ba9\u51facpu\u5e76\u6682\u505c\u81ea\u5df1\u5c31\u4f1a\u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u76f4\u5230\u83b7\u53d6cpu\u8d44\u6e90\u540e\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u7ebf\u7a0b\u6b7b\u4ea1\u540e\uff0c\u5c31\u4f1a\u8fdb\u884c\u9500\u6bc1\uff0c\u4f46\u662f\u5982\u679c\u5b58\u5728\u9700\u8981\u5927\u91cf\u7ebf\u7a0b\u53bb\u6267\u884c\u7684\u573a\u666f\u65f6\uff0c\u7ebf\u7a0b\u51fa\u73b0\u4e0d\u6b63\u5e38\u7684\u72b6\u6001\uff0c\u5bfc\u81f4\u6808\u5185\u5b58\u7a7a\u95f4\u4e0d\u65ad\u5806\u79ef\u65e0\u6cd5\u91ca\u653e\u5f88\u5bb9\u6613\u7834\u574f\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u4ee5\u53ca\u5065\u58ee\u6027\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u7c7b\u5b58\u5728\u7684\u95ee\u9898\u6216\u662f\u8d44\u6e90\u6ca1\u6709\u826f\u597d\u5229\u7528\u7684\u95ee\u9898\u5f15\u5165\u4e86\u7ebf\u7a0b\u6c60\u7684\u6982\u5ff5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ebf\u7a0b\u6c60\u4e2d\u7684\u6570\u636e\u6d41\u8f6c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"818\" src=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-6-1024x818.png\" alt=\"\" class=\"wp-image-1081\" srcset=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-6-1024x818.png 1024w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-6-300x240.png 300w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-6-768x613.png 768w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-6.png 1302w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u7531\u4efb\u52a1\u7684\u63d0\u4ea4\u8005\u63d0\u4ea4\u4efb\u52a1\uff0c\u5f53\u4efb\u52a1\u63d0\u4ea4\u540e\u9996\u5148\u4f1a\u67e5\u770b\u6838\u5fc3\u7ebf\u7a0b\u4e2d\u662f\u5426\u5b58\u5728\u53ef\u7528\u7684\u7ebf\u7a0b\uff0c\u5982\u679c\u5b58\u5728\u5c31\u521b\u5efa\u7ebf\u7a0b\u6267\u884c\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u5f53\u53d1\u73b0\u6838\u5fc3\u7ebf\u7a0b\u4e2d\u5df2\u7ecf\u6ca1\u6709\u53ef\u4ee5\u4f7f\u7528\u7684\u7ebf\u7a0b\u540e\uff0c\u8fd9\u90e8\u5206\u6ca1\u6709\u6267\u884c\u7684\u4efb\u52a1\u4f1a\u67e5\u770b\u961f\u5217\u4e2d\u662f\u5426\u8fd8\u6709\u7a7a\u7684\u4f4d\u7f6e\u80fd\u591f\u6392\u961f\uff0c\u5982\u679c\u80fd\u591f\u6392\u961f\u5219\u8fdb\u884c\u6392\u961f\u7b49\u5f85\u5206\u914d\u7ebf\u7a0b\u8fdb\u884c\u6267\u884c\uff0c\u5982\u679c\u961f\u4f0d\u5df2\u7ecf\u6ee1\u4e86\uff0c\u5219\u67e5\u770b\u7ebf\u7a0b\u6c60\u662f\u5426\u4e5f\u6ee1\u4e86\uff0c\u5982\u679c\u7ebf\u7a0b\u6c60\u4e2d\u8fd8\u6709\u53ef\u7528\u7684\u7ebf\u7a0b\uff0c\u5219\u521b\u5efa\u7ebf\u7a0b\u6267\u884c\u4efb\u52a1\uff0c\u5982\u679c\u7ebf\u7a0b\u6c60\u4e2d\u4e5f\u6ee1\u4e86\u5219\u4f1a\u4ea4\u7531\u9971\u548c\u7b56\u7565\u8fdb\u884c\u5904\u7406\uff08\u9ed8\u8ba4\u629b\u51fa\uff09\uff0c\u53ef\u4ee5\u770b\u51fa\uff0c\u5728\u7ebf\u7a0b\u6c60\u4e2d\uff0c\u505a\u4e86\u591a\u79cd\u673a\u5236\u4e3a\u4efb\u52a1\u8fdb\u884c\u7f13\u51b2\u4e0e\u515c\u5e95\uff0c\u540c\u65f6\u4e5f\u80fd\u6709\u6548\u7684\u5229\u7528\u8d44\u6e90\u63d0\u5347\u6267\u884c\u6548\u7387\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7ebf\u7a0b\u6c60\u4e2d\u5b58\u5728\u51e0\u4e2a\u6838\u5fc3\u53c2\u6570\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6838\u5fc3\u7ebf\u7a0b\u6570\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6838\u5fc3\u7ebf\u7a0b\u6570\u662f\u7ebf\u7a0b\u6c60\u4e2d\u4fdd\u6301\u5b58\u6d3b\u7684\u6700\u5c0f\u7ebf\u7a0b\u6570\u5373\u4f7f\u8fd9\u4e9b\u7ebf\u7a0b\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001\uff08\u6ca1\u6709\u6267\u884c\u4efb\u4f55\u4efb\u52a1\uff09\uff0c\u7ebf\u7a0b\u6c60\u4e5f\u4f1a\u4fdd\u6301\u81f3\u5c11\u6709\u00a0<code>corePoolSize<\/code>\u00a0\u4e2a\u7ebf\u7a0b\u5b58\u6d3b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u7279\u70b9\u4e3a\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u5728\u6ca1\u6709\u4efb\u52a1\u6267\u884c\u65f6\uff0c\u6838\u5fc3\u7ebf\u7a0b\u4e0d\u4f1a\u88ab\u9500\u6bc1\uff0c\u4f1a\u4e00\u76f4\u4fdd\u6301\u6d3b\u52a8\u72b6\u6001<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u5f53\u6709\u65b0\u4efb\u52a1\u63d0\u4ea4\u65f6\uff0c\u5982\u679c\u5f53\u524d\u6d3b\u8dc3\u7684\u7ebf\u7a0b\u6570\u5c0f\u4e8e\u00a0<code>corePoolSize<\/code>\uff08\u6838\u5fc3\u7ebf\u7a0b\u6570\u6ca1\u6ee1\uff09\uff0c\u5373\u4f7f\u4efb\u52a1\u961f\u5217\u4e2d\u6709\u4efb\u52a1\u7b49\u5f85\uff0c\u7ebf\u7a0b\u6c60\u4e5f\u4f1a\u4f18\u5148\u521b\u5efa\u65b0\u7684\u6838\u5fc3\u7ebf\u7a0b\u6765\u6267\u884c\u4efb\u52a1\uff0c\u800c\u4e0d\u662f\u5c06\u4efb\u52a1\u653e\u5165\u961f\u5217\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u786e\u5b9a<code>corePoolSize<\/code>\u7ebf\u7a0b\u6570\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u822c\u6765\u8bf4\u4f1a\u5c06\u4efb\u52a1\u5206\u4e3aio\u5bc6\u96c6\u578b\u8fd8\u662fcpu\u5bc6\u96c6\u578b\uff0c\u901a\u4fd7\u6765\u8bf4io\u5bc6\u96c6\u578b\u591a\u504f\u5411\u7f51\u7edc\u4f20\u8f93\uff0c\u6587\u4ef6\u3001\u6570\u636e\u7b49\u591aio\u64cd\u4f5c\u800ccup\u5bc6\u96c6\u578b\u5c31\u662f\u6307\u4efb\u52a1\u591a\u504f\u5411\u5728\u5185\u5b58\u4e2d\u8fdb\u884c\u5904\u7406\u4e0e\u8ba1\u7b97\uff0c\u6839\u636e\u4e0d\u540c\u7684\u7c7b\u578b\u5bf9<code>corePoolSize<\/code>\u7ebf\u7a0b\u6570\u8fdb\u884c\u8ba1\u7b97\uff0c\u5bf9\u4e8ecpu\u5bc6\u96c6\u578b\u8f83\u591a\u7684\u4efb\u52a1\u4e00\u822c\u5b9a\u4e49\u4e3a\u4e0ecpu\u76f8\u540c\u7684\u7ebf\u7a0b\u6570\u800cio\u5bc6\u96c6\u578b\u5219\u662fcpu\u7ebf\u7a0b\u6570\u7684\u4e24\u500d\u6216\u4e24\u500d\u51cf\u4e00\uff08\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6570\u4e3b\u7ebf\u7a0b\uff09\u8fd9\u6837\u5b9a\u4e49\u662f\u7531\u4e8eio\u5bc6\u96c6\u578b\u7684\u8d1f\u8f7d\u5e76\u4e0d\u5728\u672c\u5730\uff0c\u6240\u4ee5\u538b\u529b\u4e0d\u4f1a\u5f88\u5927\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7java\u81ea\u5e26\u7684\u5de5\u5177\u5305\u4e2d\u7684\u4e00\u4e2a\u65b9\u6cd5\u83b7\u53d6\u5230\u6267\u884c\u5f53\u524d\u4efb\u52a1\u7684\u8fd9\u53f0\u673a\u5668\u4e0a\u7684cpu\u6838\u5fc3\u6570\u662f\u591a\u5c11\uff0c\u4ece\u800c\u4e0d\u7528\u518d\u6362\u4e0d\u540c\u670d\u52a1\u5668\u65f6\u518d\u6b21\u5bf9\u5176\u8c03\u6574<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Runtime.getRuntime().availableProcessors();\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9\">Runtime<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getRuntime<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">availableProcessors<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6e90\u7801\u4ee5\u53ca\u6ce8\u91ca\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"    \/**\n     * Returns the number of processors available to the Java virtual machine.\n     *\n     * &lt;p&gt; This value may change during a particular invocation of the virtual\n     * machine.  Applications that are sensitive to the number of available\n     * processors should therefore occasionally poll this property and adjust\n     * their resource usage appropriately. &lt;\/p&gt;\n     *\n     * @return  the maximum number of processors available to the virtual\n     *          machine; never smaller than one\n     * @since 1.4\n     *\/\n    public native int availableProcessors();\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\">    \/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * Returns the number of processors available to the Java virtual machine.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * &lt;p&gt; This value may change during a particular invocation of the virtual<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * machine.  Applications that are sensitive to the number of available<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * processors should therefore occasionally poll this property and adjust<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * their resource usage appropriately. &lt;\/p&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * <\/span><span style=\"color: #8FBCBB\">@return<\/span><span style=\"color: #616E88\">  the maximum number of processors available to the virtual<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     *          machine; never smaller than one<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     * <\/span><span style=\"color: #8FBCBB\">@since<\/span><span style=\"color: #616E88\"> 1.4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">     *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">native<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">availableProcessors<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6700\u5927\u7ebf\u7a0b\u6570\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u5927\u7ebf\u7a0b\u6570\u5c31\u662f\u5f53\u961f\u5217\u4e2d\u653e\u4e0d\u4e0b\u4e14\u6838\u5fc3\u7ebf\u7a0b\u6570\u4e5f\u6ee1\u4e86\u7684\u65f6\u5019\u7684\u4e00\u4e2a\u515c\u5e95\uff0c\u662f\u6307\u7ebf\u7a0b\u6c60\u4e2d\u80fd\u5bb9\u7eb3\u7684\u6700\u5927\u7ebf\u7a0b\u6570\u91cf\uff0c\u7ebf\u7a0b\u6c60\u4f1a\u521b\u5efa\u989d\u5916\u7684\u7ebf\u7a0b\uff0c\u76f4\u5230\u7ebf\u7a0b\u603b\u6570\u8fbe\u5230\u6700\u5927\u7ebf\u7a0b\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7279\u70b9\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u5f53\u6838\u5fc3\u7ebf\u7a0b\u90fd\u5728\u5fd9\u788c\uff0c\u4e14\u4efb\u52a1\u961f\u5217\u5df2\u6ee1\u65f6\uff0c\u7ebf\u7a0b\u6c60\u4f1a\u521b\u5efa\u975e\u6838\u5fc3\u7ebf\u7a0b\u6765\u6267\u884c\u4efb\u52a1\u3002\u975e\u6838\u5fc3\u7ebf\u7a0b\u4e00\u65e6\u7a7a\u95f2\u4e14\u8d85\u8fc7\u5b58\u6d3b\u8bbe\u7f6e\u7684\u65f6\u95f4\uff0c\u5219\u4f1a\u88ab\u56de\u6536\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u975e\u6838\u5fc3\u7ebf\u7a0b\u7684\u5b58\u5728\u662f\u4e3a\u4e86\u5e94\u5bf9\u77ed\u671f\u7684\u7a81\u53d1\u4efb\u52a1\u9700\u6c42\uff0c\u63d0\u5347\u7ebf\u7a0b\u6c60\u7684\u5e76\u53d1\u80fd\u529b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u5f53\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u6570\u8fbe\u6700\u5927\u7ebf\u7a0b\u6570\u65f6\uff0c\u5982\u679c\u7ee7\u7eed\u6709\u65b0\u4efb\u52a1\u63d0\u4ea4\uff0c\u800c\u4efb\u52a1\u961f\u5217\u53c8\u6ee1\u4e86\uff0c\u5219\u6839\u636e\u62d2\u7edd\u7b56\u7565\u5904\u7406\uff08\u5982\u629b\u51fa\u5f02\u5e38\u3001\u4e22\u5f03\u4efb\u52a1\u7b49\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u961f\u5217\uff08\u963b\u585e\/\u666e\u901a\uff09\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5206\u4e3a\u963b\u585e\u961f\u5217\u4e0e\u666e\u901a\u7684\u961f\u5217\uff08LinkedList\/ArrayList\uff09\u76f8\u6bd4\uff0c\u652f\u6301\u5728\u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u5143\u7d20\u65f6\uff0c\u961f\u5217\u7684\u957f\u5ea6\u5df2\u6ee1\u963b\u585e\u5f53\u524d\u6dfb\u52a0\u7ebf\u7a0b\uff0c\u76f4\u5230\u961f\u5217\u672a\u6ee1\u6216\u8005\u7b49\u5f85\u8d85\u65f6\uff1b\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u5143\u7d20\u65f6\uff0c\u961f\u5217\u4e2d\u5143\u7d20\u4e3a\u7a7a \uff0c\u4f1a\u5c06\u83b7\u53d6\u5143\u7d20\u7684\u7ebf\u7a0b\u963b\u585e\uff0c\u76f4\u5230\u961f\u5217\u4e2d\u5b58\u5728\u5143\u7d20 \u6216\u8005\u7b49\u5f85\u8d85\u65f6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f7f\u7528\u573a\u666f\uff1a<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u666e\u901a\u961f\u5217\uff08Queue\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9002\u7528\u4e8e\u5355\u7ebf\u7a0b\u73af\u5883<\/strong>: \u7528\u4e8e\u7b80\u5355\u7684\u5148\u8fdb\u5148\u51fa\uff08FIFO\uff09\u6570\u636e\u7ed3\u6784\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e0d\u9700\u8981\u963b\u585e\u7b49\u5f85<\/strong>: \u9002\u7528\u4e8e\u4e0d\u9700\u8981\u7b49\u5f85\u961f\u5217\u53ef\u7528\u6216\u961f\u5217\u5143\u7d20\u53ef\u7528\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u963b\u585e\u961f\u5217\uff08Blocking Queue\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9002\u7528\u4e8e\u591a\u7ebf\u7a0b\u73af\u5883<\/strong>: \u5e38\u7528\u4e8e\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u6a21\u5f0f\uff0c\u751f\u4ea7\u8005\u7ebf\u7a0b\u53ef\u4ee5\u5c06\u5143\u7d20\u6dfb\u52a0\u5230\u961f\u5217\u4e2d\uff0c\u6d88\u8d39\u8005\u7ebf\u7a0b\u53ef\u4ee5\u4ece\u961f\u5217\u4e2d\u53d6\u51fa\u5143\u7d20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9700\u8981\u963b\u585e\u7b49\u5f85<\/strong>: \u9002\u7528\u4e8e\u9700\u8981\u7b49\u5f85\u961f\u5217\u7a7a\u95f4\u6216\u7b49\u5f85\u961f\u5217\u5143\u7d20\u7684\u573a\u666f\uff0c\u5982\u4efb\u52a1\u8c03\u5ea6\u3001\u6d88\u606f\u4f20\u9012\u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ebf\u7a0b\u5b89\u5168\u6027<\/strong>\uff1a<br><strong>\u975e\u7ebf\u7a0b\u5b89\u5168<\/strong>: \u666e\u901a\u961f\u5217\u901a\u5e38\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u5982\u679c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u9700\u8981\u624b\u52a8\u8fdb\u884c\u540c\u6b65\u63a7\u5236\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u963b\u585e\u961f\u5217\uff08Blocking Queue\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ebf\u7a0b\u5b89\u5168<\/strong>: \u963b\u585e\u961f\u5217\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u652f\u6301\u591a\u7ebf\u7a0b\u5e76\u53d1\u64cd\u4f5c\uff0c\u5185\u90e8\u5b9e\u73b0\u4e86\u5fc5\u8981\u7684\u540c\u6b65\u673a\u5236\uff0c\u65e0\u9700\u5916\u90e8\u540c\u6b65\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728JUC\u5305\u4e2d\u5e38\u7528\u7684\u963b\u585e\u961f\u5217\u5305\u542bArrayBlockingQueue\/LinkedBlockingQueue\/LinkedBlockingDeque\u7b49\uff0c\u4ece\u7ed3\u6784\u6765\u770b\u90fd\u7ee7\u627f\u4e86AbstractQueue\u5b9e\u73b0\u4e86BlockingQueue\u63a5\u53e3\uff08LinkedBlockingDeque\u662f\u53cc\u5411\u963b\u585e\u961f\u5217\uff0c\u5b9e\u73b0\u7684\u662fBlockingDeque\u63a5\u53e3\uff09\uff0c\u5728BlockingQueue\u63a5\u53e3\u4e2d\u5b9a\u4e49\u4e86\u51e0\u4e2a\u4f9b\u5b50\u7c7b\u5b9e\u73b0\u7684\u63a5\u53e3\uff0c\u53ef\u4ee5\u5206\u4e3a3\u90e8\u5206\uff0cputs\u64cd\u4f5c\u3001takes\u64cd\u4f5c\u3001\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u963b\u585e\u961f\u5217ArrayBlockingQueue\u4e0eLinkedBlockingQueue\u7684\u533a\u522b\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LinkedBlockingQueue<\/code>\u00a0\u548c\u00a0<code>ArrayBlockingQueue<\/code>\u00a0\u90fd\u662f Java \u4e2d\u00a0<code>java.util.concurrent<\/code>\u00a0\u5305\u63d0\u4f9b\u7684\u963b\u585e\u961f\u5217\u5b9e\u73b0\uff0c\u7528\u4e8e\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7684\u5e76\u53d1\u64cd\u4f5c\u3002\u5b83\u4eec\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7684\u5b9e\u73b0\u65b9\u5f0f\u4ee5\u53ca\u4e00\u4e9b\u7279\u6027\u548c\u884c\u4e3a\u4e0a\u7684\u5dee\u5f02\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e95\u5c42\u6570\u636e\u7ed3\u6784<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>LinkedBlockingQueue<\/strong>\uff1a\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6709\u754c\/\u65e0\u754c\u963b\u585e\u961f\u5217\u3002\u5185\u90e8\u4f7f\u7528\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u6765\u5b58\u50a8\u5143\u7d20\u3002\u94fe\u8868\u7684\u6bcf\u4e2a\u8282\u70b9\uff08Node\uff09\u5305\u542b\u4e00\u4e2a\u5143\u7d20\u548c\u6307\u5411\u524d\u9a71\u548c\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ArrayBlockingQueue<\/strong>\uff1a\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6709\u754c\u963b\u585e\u961f\u5217\u3002\u5185\u90e8\u4f7f\u7528\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u6765\u5b58\u50a8\u5143\u7d20\uff0c\u5e76\u4e14\u5728\u521b\u5efa\u65f6\u5fc5\u987b\u6307\u5b9a\u6570\u7ec4\u7684\u5927\u5c0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5bb9\u91cf<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>LinkedBlockingQueue<\/strong>\uff1a\u53ef\u4ee5\u662f\u6709\u754c\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u65e0\u754c\u7684\uff08\u9ed8\u8ba4\u662f\u65e0\u754c\u7684\uff09\u3002\u5bf9\u4e8e\u6709\u754c\u7684\u00a0<code>LinkedBlockingQueue<\/code>\uff0c\u53ef\u4ee5\u5728\u521b\u5efa\u65f6\u6307\u5b9a\u5bb9\u91cf\uff1b\u5bf9\u4e8e\u65e0\u754c\u7684\u00a0<code>LinkedBlockingQueue<\/code>\uff0c\u5bb9\u91cf\u4e3a\u00a0<code>Integer.MAX_VALUE<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ArrayBlockingQueue<\/strong>\uff1a\u59cb\u7ec8\u662f\u6709\u754c\u7684\uff0c\u521b\u5efa\u65f6\u5fc5\u987b\u6307\u5b9a\u5bb9\u91cf\uff0c\u4e14\u5bb9\u91cf\u4e00\u65e6\u786e\u5b9a\u5c31\u4e0d\u80fd\u66f4\u6539\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ebf\u7a0b\u5b89\u5168\u6027<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u8005\u90fd\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u90fd\u4f7f\u7528\u4e86\u5185\u90e8\u9501\uff08<code>ReentrantLock<\/code>\uff09\u6765\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168\u6027\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> \u6027\u80fd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>LinkedBlockingQueue<\/strong>\uff1a\u5728\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u65f6\uff0c\u7531\u4e8e\u4f7f\u7528\u94fe\u8868\u7ed3\u6784\uff0c\u4e0d\u9700\u8981\u79fb\u52a8\u5143\u7d20\uff0c\u56e0\u6b64\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u6027\u80fd\u8f83\u9ad8\u3002\u4f46\u7531\u4e8e\u94fe\u8868\u7684\u8282\u70b9\u9700\u8981\u989d\u5916\u7684\u6307\u9488\uff0c\u56e0\u6b64\u5185\u5b58\u5360\u7528\u53ef\u80fd\u8f83\u9ad8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ArrayBlockingQueue<\/strong>\uff1a\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u65f6\uff0c\u7531\u4e8e\u662f\u57fa\u4e8e\u6570\u7ec4\u7684\uff0c\u53ef\u80fd\u9700\u8981\u79fb\u52a8\u5143\u7d20\uff0c\u56e0\u6b64\u6027\u80fd\u7565\u4f4e\u4e8e\u00a0<code>LinkedBlockingQueue<\/code>\u3002\u4f46\u7531\u4e8e\u6570\u7ec4\u7ed3\u6784\u7684\u5185\u5b58\u8fde\u7eed\u6027\uff0c\u5185\u5b58\u5360\u7528\u76f8\u5bf9\u8f83\u4f4e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u516c\u5e73\u6027<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ArrayBlockingQueue<\/strong>\uff1a\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u4f7f\u7528\u516c\u5e73\u9501\uff08fair lock\uff09\uff0c\u5373\u5148\u5230\u5148\u5f97\u7684\u539f\u5219\uff08\u9ed8\u8ba4\u662f\u975e\u516c\u5e73\u7684\uff09\u3002\u4f7f\u7528\u516c\u5e73\u9501\u4f1a\u589e\u52a0\u7b49\u5f85\u7ebf\u7a0b\u7684\u7b49\u5f85\u65f6\u95f4\uff0c\u4f46\u53ef\u4ee5\u907f\u514d\u7ebf\u7a0b\u9965\u997f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>LinkedBlockingQueue<\/strong>\uff1a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u975e\u516c\u5e73\u7684\uff0c\u4e0d\u652f\u6301\u516c\u5e73\u9501\u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u573a\u666f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>LinkedBlockingQueue<\/strong>\uff1a\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u541e\u5410\u91cf\u7684\u573a\u666f\uff0c\u7279\u522b\u662f\u5728\u961f\u5217\u957f\u5ea6\u53ef\u80fd\u4e0d\u786e\u5b9a\u6216\u52a8\u6001\u53d8\u5316\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ArrayBlockingQueue<\/strong>\uff1a\u9002\u7528\u4e8e\u9700\u8981\u56fa\u5b9a\u961f\u5217\u5927\u5c0f\u7684\u573a\u666f\uff0c\u7279\u522b\u662f\u5728\u5185\u5b58\u5360\u7528\u548c\u6027\u80fd\u4e4b\u95f4\u9700\u8981\u5e73\u8861\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u603b\u7ed3\uff1a<strong>LinkedBlockingQueue<\/strong>\u9002\u7528\u4e8e\u52a8\u6001\u961f\u5217\u5927\u5c0f\uff0c\u9ad8\u541e\u5410\u91cf\u7684\u573a\u666f\uff0c<strong>ArrayBlockingQueue<\/strong>\u9002\u7528\u4e8e\u56fa\u5b9a\u961f\u5217\u5927\u5c0f\uff0c\u5bf9\u5185\u5b58\u5360\u7528\u6709\u4e00\u5b9a\u8981\u6c42\u7684\u573a\u666f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e3a\u4ec0\u4e48\u4f7f\u7528\u591a\u7ebf\u7a0b\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u4e0a\u9762\u7684\u63cf\u8ff0\u53ef\u4ee5\u77e5\u9053\uff0c\u7ebf\u7a0b\u6c60\u662f\u4e00\u4e2a\u5b58\u653e\u7ebf\u7a0b\u5e76\u53ef\u4ee5\u6301\u7eed\u5229\u7528\u7684\u5de5\u5177\uff0c\u6709\u7740\u5f88\u591a\u53c2\u6570\u4e0e\u7b56\u7565\u7528\u4e8e\u63d0\u5347\u4efb\u52a1\u7684\u6548\u7387\u4e0e\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u5bf9\u4e8e\u6211\u4f7f\u7528\u7684\u591a\u7ebf\u7a0b\u63d2\u5165\u6570\u636e\u7684\u65b9\u6cd5\u8fdb\u884c\u4e00\u4e2a\u8bb2\u89e3\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u4f7f\u7528StopWatch\u7c7b\u5bf9\u6267\u884c\u65f6\u95f4\u8fdb\u884c\u4e00\u4e2a\u8bb0\u5f55\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"        \/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\n        StopWatch stopWatch = new StopWatch();\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">StopWatch<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">StopWatch<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6ca1\u6709\u4f7f\u7528\u9ed8\u8ba4\u7684\u7ebf\u7a0b\u6c60\uff08ForkJoinPool\uff09\uff0c\u56e0\u4e3a\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff08\u5f53CPU\u6838\u5fc3\u6570-1\u5927\u4e8e1\u65f6\uff0c\u624d\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u7684\u7ebf\u7a0b\u6c60\uff0c\u5426\u5219\u5c06\u4f1a\u4e3a\u6bcf\u4e2aCompletableFuture\u7684\u4efb\u52a1\u521b\u5efa\u4e00\u4e2a\u65b0\u7ebf\u7a0b\u53bb\u6267\u884c\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5047\u5982\u6211\u4eec\u5c06\u670d\u52a1\u4ece\u4e00\u53f0\u673a\u5668\u8fc1\u79fb\u81f3\u53e6\u5916\u4e00\u53f0\u673a\u5668\u65f6\uff0c\u78b0\u5de7\u8fd9\u53f0\u673a\u5668\u7684cpu\u53ea\u67092\u4e2a\u6838\u5fc3\uff0c\u8fd9\u65f6\u5219\u4e0d\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u800c\u662f\u76f4\u63a5\u521b\u5efa\u7ebf\u7a0b\u4efb\u52a1\uff0c\u4e00\u822c\u6765\u8bf4\u4f7f\u7528\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u7684\u573a\u666f\u66f4\u591a\u662f\u4ee5cpu\u5bc6\u96c6\u578b\u7684\u4efb\u52a1\u4e3a\u4e3b\uff09\u8fd9\u90e8\u5206\u7684\u8be6\u7ec6\u89e3\u8bfb\u53ef\u4ee5\u53c2\u8003\u8fd9\u4f4d\u535a\u4e3b\u7684\u6587\u7ae0\uff1a<a href=\"https:\/\/www.cnblogs.com\/blackmlik\/p\/16098938.html\">https:\/\/www.cnblogs.com\/blackmlik\/p\/16098938.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u662f\u5bf9\u6570\u636e\u5e93\u7684\u5199\u64cd\u4f5c\uff0c\u6240\u4ee5\u662f\u4ee5io\u5bc6\u96c6\u578b\u4e3a\u4e3b\uff0c\u8fd9\u91cc\u5b9a\u4e49\u4e86\u6838\u5fc3\u7ebf\u7a0b\u6570\u4e3acpu\u6838\u5fc3\u6570\u76842\u500d\uff08\u6216\u8005\u53ef\u4ee5\u5b9a\u4e49\u4e3acpu\u6838\u5fc3\u6570\u76842\u500d\u51cf1\uff09\uff0c\u6700\u5927\u7ebf\u7a0b\u6570\u5219\u8bbe\u7f6e\u4e3acpu\u6838\u5fc3\u6570\u76842\u52304\u500d\uff0c\u963b\u585e\u961f\u5217\u8fd9\u91cc\u7531\u4e8e\u6ca1\u6709\u8f83\u5927\u5e76\u53d1\u6216\u8005\u6d77\u91cf\u6570\u636e\u7684\u573a\u666f\uff0c\u6240\u4ee5\u9009\u7528\u4e86\u56fa\u5b9a\u53ef\u63a7\u7684\u963b\u585e\u961f\u5217\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"        \/\/\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\n        ThreadPoolExecutor threadPoolExecutor =\n                new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors()*2,\n                        80,\n                        10000,\n                        TimeUnit.MINUTES,\n                        new ArrayBlockingQueue&lt;&gt;(1000));\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">ThreadPoolExecutor<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">threadPoolExecutor<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">ThreadPoolExecutor<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">Runtime<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getRuntime<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">availableProcessors<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #B48EAD\">80<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #B48EAD\">10000<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #D8DEE9\">TimeUnit<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">MINUTES<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                        <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayBlockingQueue<\/span><span style=\"color: #ECEFF4\">&lt;&gt;(<\/span><span style=\"color: #B48EAD\">1000<\/span><span style=\"color: #ECEFF4\">))<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efaCompletableFuture\u5f02\u6b65\u4efb\u52a1\uff0c\u5728\u5f02\u6b65\u4efb\u52a1\u4e2d\u4f7f\u7528\u6211\u4eec\u81ea\u5df1\u521b\u5efa\u7684\u7ebf\u7a0b\u6c60\uff0c\u5728\u4efb\u52a1\u4e2d\u8fdb\u884c\u6279\u91cf\u63d2\u5165\u6570\u636e\uff0c\u5e76\u5c06\u521b\u5efa\u597d\u7684\u4efb\u52a1\u6dfb\u52a0\u5230\u4e00\u6b65\u4efb\u52a1\u5217\u8868\u4e2d\uff0c\u4ece\u4ee3\u7801\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u662f\u5c06\u6570\u636e\u62c6\u5206\u6210\u4e8620\u4e2a\u5f02\u6b65\u4efb\u52a1\uff0c\u653e\u5165\u5230\u5217\u8868\u4e2d\uff0c\u6bcf\u6279\u63d2\u516550000\u6761\u6570\u636e\uff0c\u4e00\u5171\u4e00\u767e\u4e07\u6761\u6570\u636e<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"        \/\/\u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\u5217\u8868\n        List&lt;CompletableFuture&lt;Void&gt;&gt; futures = new ArrayList&lt;&gt;();\n        \/\/\u5faa\u73af\u63d2\u5165\u6570\u636e\n        int j = 0;\n        for (int i = 0; i &lt;20; i++) {\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u7528\u6237\u5217\u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u6279\u7528\u6237\u6570\u636e\n            ArrayList&lt;User&gt; userList = new ArrayList&lt;&gt;();\n            do {\n                j++;\n                User user = getUser(j);\n                userList.add(user);\n            } while (j % batch_insert != 0);\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230futures\u5217\u8868\u4e2d\uff0c\u4e3a\u4efb\u52a1\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\n            CompletableFuture&lt;Void&gt; future = CompletableFuture.runAsync(() -&gt; {\n                System.out.println(&quot;\u7ebf\u7a0b&quot;+Thread.currentThread().getName()+&quot;\u6267\u884c&quot;);\n                userService.saveBatch(userList, 10000);\n                userList.clear();\n            }, threadPoolExecutor);\n            \/\/ \u5c06\u5f02\u6b65\u4efb\u52a1\u52a0\u5165\u5230futures\u5217\u8868\u4e2d\n            futures.add(future);\n        }\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #8FBCBB\">List<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">Void<\/span><span style=\"color: #ECEFF4\">&gt;&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;&gt;()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u5faa\u73af\u63d2\u5165\u6570\u636e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">j<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> i <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #B48EAD\">20<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> i<\/span><span style=\"color: #81A1C1\">++<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u521b\u5efa\u4e00\u4e2a\u7528\u6237\u5217\u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u6279\u7528\u6237\u6570\u636e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #ECEFF4\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ArrayList<\/span><span style=\"color: #ECEFF4\">&lt;&gt;()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">do<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                j<\/span><span style=\"color: #81A1C1\">++;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #8FBCBB\">User<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">user<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">getUser<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">j<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">add<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">user<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">while<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">j <\/span><span style=\"color: #81A1C1\">%<\/span><span style=\"color: #D8DEE9FF\"> batch_insert <\/span><span style=\"color: #81A1C1\">!=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u4efb\u52a1\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230futures\u5217\u8868\u4e2d\uff0c\u4e3a\u4efb\u52a1\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">&lt;<\/span><span style=\"color: #8FBCBB\">Void<\/span><span style=\"color: #ECEFF4\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">future<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">runAsync<\/span><span style=\"color: #ECEFF4\">(()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">-&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">System<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">out<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">println<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u7ebf\u7a0b<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9\">Thread<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">currentThread<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">getName<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u6267\u884c<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userService<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">saveBatch<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">userList<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">10000<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #D8DEE9\">userList<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">clear<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #ECEFF4\">},<\/span><span style=\"color: #D8DEE9FF\"> threadPoolExecutor<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">            <\/span><span style=\"color: #616E88\">\/\/ \u5c06\u5f02\u6b65\u4efb\u52a1\u52a0\u5165\u5230futures\u5217\u8868\u4e2d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">add<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">future<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u6267\u884c\u4efb\u52a1\u5217\u8868\u4e2d\u7684\u4efb\u52a1<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"        \/\/ \u6267\u884c\u6240\u6709\u5f02\u6b65\u4efb\u52a1\n        CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join();\n        \/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4\n        stopWatch.stop();\n        System.out.println(&quot;\u6267\u884c\u6700\u7ec8\u7528\u65f6:&quot;+stopWatch.getTotalTimeMillis());\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/ \u6267\u884c\u6240\u6709\u5f02\u6b65\u4efb\u52a1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">allOf<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">futures<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">toArray<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">CompletableFuture<\/span><span style=\"color: #ECEFF4\">[]{})).<\/span><span style=\"color: #88C0D0\">join<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/\u8bb0\u5f55\u6267\u884c\u65f6\u95f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">stop<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #D8DEE9\">System<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">out<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">println<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">\u6267\u884c\u6700\u7ec8\u7528\u65f6:<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9\">stopWatch<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getTotalTimeMillis<\/span><span style=\"color: #ECEFF4\">())<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u5f53\u6211\u6b63\u6267\u884c\u65f6\u53d1\u751f\u4e86\u62a5\u9519<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"java.util.concurrent.CompletionException: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30006ms.\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9\">java<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">util<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">concurrent<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">CompletionException<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">org<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">springframework<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">transaction<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">CannotCreateTransactionException<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Could<\/span><span style=\"color: #D8DEE9FF\"> not open <\/span><span style=\"color: #8FBCBB\">JDBC<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Connection<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">transaction<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> nested exception is <\/span><span style=\"color: #D8DEE9\">java<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">sql<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">SQLTransientConnectionException<\/span><span style=\"color: #81A1C1\">:<\/span><span style=\"color: #D8DEE9FF\"> HikariPool<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">Connection<\/span><span style=\"color: #D8DEE9FF\"> is not available<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> request timed out after 30006ms<\/span><span style=\"color: #ECEFF4\">.<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><br>\u62a5\u9519\u539f\u56e0\uff1a\u5e94\u7528\u7a0b\u5e8f\u5728\u5c1d\u8bd5\u83b7\u53d6\u6570\u636e\u5e93\u8fde\u63a5\u65f6\u9047\u5230\u4e86\u95ee\u9898\uff0c\u5177\u4f53\u8868\u73b0\u4e3a\u8fde\u63a5\u6c60\u4e2d\u7684\u8fde\u63a5\u5df2\u7ecf\u8017\u5c3d\uff0c\u4e14\u5728\u8d85\u65f6\u65f6\u95f4\uff0830,006\u6beb\u79d2\uff09\u5185\u65e0\u6cd5\u83b7\u5f97\u53ef\u7528\u8fde\u63a5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8e\u662f\u7b2c\u4e00\u65f6\u95f4\u67e5\u770b\u4e86mysql\u7684\u6700\u5927\u8fde\u63a5\u6570<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SHOW VARIABLES LIKE 'max_connections';\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">SHOW VARIABLES <\/span><span style=\"color: #81A1C1\">LIKE<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">max_connections<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"338\" height=\"98\" src=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-7.png\" alt=\"\" class=\"wp-image-1104\" srcset=\"https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-7.png 338w, https:\/\/www.coffecat.cn\/wp-content\/uploads\/2024\/11\/image-7-300x87.png 300w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u6211\u5b9e\u9645\u4f7f\u7528\u4e86100\u4e2a\u4e14\u90fd\u8fd8\u662f\u5f02\u6b65\u7684\uff0c\u4e0d\u5e94\u8be5\u51fa\u73b0\u8017\u5c3d\u7684\u95ee\u9898\uff0c\u4ed4\u7ec6\u67e5\u770b\u662f\u8fde\u63a5\u6c60\u4e2d\u7684\u8fde\u63a5\u6570\u5df2\u7ecf\u8017\u5c3d\uff0c\u4e8e\u662f\u8c03\u6574\u4e86\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u6570<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"    hikari:\n      idle-timeout: 600000 #\u7a7a\u95f2\u8fde\u63a5\n      minimum-idle: 10  #\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\n      maximum-pool-size: 40 #\u6700\u5927\u8fde\u63a5\u6570\n      max-lifetime: 30000   #\u4e0d\u80fd\u5c0f\u4e8e30\u79d2\uff0c\u5426\u5219\u9ed8\u8ba4\u56de\u52301800\u79d2\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">    hikari:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">      idle-timeout: 600000 #\u7a7a\u95f2\u8fde\u63a5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">      minimum-idle: 10  #\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">      maximum-pool-size: 40 #\u6700\u5927\u8fde\u63a5\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">      max-lifetime: 30000   #\u4e0d\u80fd\u5c0f\u4e8e30\u79d2\uff0c\u5426\u5219\u9ed8\u8ba4\u56de\u52301800\u79d2<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u51fa\u73b0\u00a0SQLTransientConnectionException: HikariPool-1 &#8211; Connection is not available\u00a0\u5f02\u5e38\u901a\u5e38\u662f\u7531\u4e8e\u8fde\u63a5\u6c60\u4e2d\u7684\u8fde\u63a5\u8017\u5c3d\u6216\u8fde\u63a5\u83b7\u53d6\u8d85\u65f6\u5bfc\u81f4\u7684\u3002\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u9700\u8981\u4ece\u8fde\u63a5\u6c60\u914d\u7f6e\u3001\u6570\u636e\u5e93\u6027\u80fd\u3001\u4ee3\u7801\u903b\u8f91\u7b49\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u6392\u67e5\u548c\u4f18\u5316\u3002\u901a\u8fc7\u8c03\u6574\u8fde\u63a5\u6c60\u914d\u7f6e\u3001\u4f18\u5316\u6570\u636e\u5e93\u64cd\u4f5c\u548c\u68c0\u67e5\u6570\u636e\u5e93\u670d\u52a1\u5668\u6027\u80fd\uff0c\u53ef\u4ee5\u6709\u6548\u51cf\u5c11\u6b64\u7c7b\u5f02\u5e38\u7684\u53d1\u751f\u3002\u800c\u6211\u8fd9\u91cc\u7ecf\u8fc7\u6392\u67e5\u53d1\u73b0\u5c31\u662f\u56e0\u4e3a\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u6570\u8bbe\u7f6e\u7684\u4e0d\u5408\u7406\u5bfc\u81f4\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8100w\u6761\u6570\u636e\u63d2\u5165\u7684\u65f6\u95f4\u662f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\u6267\u884c\u6700\u7ec8\u7528\u65f6:35890\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">\u6267\u884c\u6700\u7ec8\u7528\u65f6:35890<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u5bf9\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u6570\u53c8\u505a\u4e86\u4e00\u4e9b\u8c03\u6574<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"maximum-pool-size: 110 #\u6700\u5927\u8fde\u63a5\u6570\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">maximum-pool-size: 110 #\u6700\u5927\u8fde\u63a5\u6570<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">100w\u6761\u6570\u636e\u63d2\u5165\u7684\u65f6\u95f4\u662f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\u6267\u884c\u6700\u7ec8\u7528\u65f6:30821\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">\u6267\u884c\u6700\u7ec8\u7528\u65f6:30821<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u53d1\u73b0\u53ef\u4ee5\u572830s\u5de6\u53f3\u63d2\u5165100w\u6761\u6570\u636e\uff0c\u4f46\u662f\u8fd9\u91cc\u8981\u6ce8\u610f\uff0c\u5728\u771f\u6b63\u7684\u751f\u4ea7\u573a\u666f\u4e2d\u662f\u9700\u8981\u6839\u636e\u4e1a\u52a1\u573a\u666f\u53bb\u505a\u8c03\u6574\u7684\uff0c\u8fd9\u91cc\u53ea\u662f\u7406\u60f3\u72b6\u6001\u4e0b\u8ba9\u4efb\u52a1\u8dd1\u5728\u4e86\u81ea\u5df1\u8bbe\u5b9a\u597d\u7684\u201c\u8212\u9002\u533a\u201d\uff0c\u8fd9\u6837\u662f\u53ef\u4ee5\u66f4\u5feb\u7684\u5b8c\u6210\u8fd9\u4e2a\u5feb\u901f\u63d2\u5165\u5927\u91cf\u6570\u636e\u7684\u4efb\u52a1\uff0c\u4f46\u662f\u5728\u6267\u884c\u4efb\u52a1\u7684\u8fd9\u4e00\u65f6\u523b\uff0c\u6709\u5176\u4ed6\u7684\u670d\u52a1\u6216\u8005\u5176\u4ed6\u7684\u4efb\u52a1\u5728\u4f7f\u7528\u5219\u53ef\u80fd\u4f1a\u51fa\u73b0\u95ee\u9898\uff0c\u5bf9\u4e8eSpring Boot Hikari\u8fde\u63a5\u6c60\uff0c\u5728\u6b63\u5f0f\u73af\u5883\u4e2d\u5176\u5b9e\u53ef\u4ee5\u4f7f\u7528\u52a8\u6001\u8c03\u6574\u7684\u65b9\u5f0f\u53bb\u81ea\u52a8\u8c03\u6574\u6700\u5927\u8fde\u63a5\u6570\uff0c\u8fd9\u6837\u5728\u591a\u670d\u52a1\u4f7f\u7528\u540c\u4e00\u4e2a\u6570\u636e\u5e93\u7684\u573a\u666f\u4e0b\u4e5f\u4f1a\u51cf\u7f13\u6216\u8005\u8bf4\u63d0\u9ad8\u8fde\u63a5\u6c60\u7684\u5229\u7528\u7387\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u501f\u52a9Spring Boot\u7684@Scheduled\u6ce8\u89e3\uff0c\u5b9a\u671f\u8c03\u8282\u8fde\u63a5\u6c60\u53c2\u6570\uff0c\u8fd9\u91cc\u53c2\u8003\u4e86\u535a\u4e3b\u7684\u6587\u7ae0\uff1a<a href=\"https:\/\/blog.51cto.com\/u_16175520\/11678069\">https:\/\/blog.51cto.com\/u_16175520\/11678069<\/a><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import org.springframework.scheduling.annotation.Scheduled;\nimport org.springframework.stereotype.Service;\n@Service\npublic class ConnectionPoolAdjuster {\n    @Autowired\n    private HikariDataSource dataSource;\n    @Scheduled(fixedRate = 60000)\n    public void adjustPoolSize() {\n        int currentActive = dataSource.getHikariPoolMXBean().getActiveConnections();\n        int maxPoolSize = dataSource.getMaximumPoolSize();\n        \n        \/\/ \u6839\u636e\u5f53\u524d\u6d3b\u52a8\u8fde\u63a5\u6570\u8c03\u8282\u6700\u5927\u8fde\u63a5\u6c60\u5927\u5c0f\n        if (currentActive &gt; maxPoolSize - 2) {\n            int newSize = maxPoolSize + 2;\n            dataSource.setMaximumPoolSize(newSize);\n            System.out.println(&quot;Increasing max pool size to: &quot; + newSize);\n        }\n    }\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">org<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">springframework<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">scheduling<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">annotation<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">Scheduled<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">org<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">springframework<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">stereotype<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #8FBCBB\">Service<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">@<\/span><span style=\"color: #D08770\">Service<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">class<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">ConnectionPoolAdjuster<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">@<\/span><span style=\"color: #D08770\">Autowired<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">private<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">HikariDataSource<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">dataSource<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">@<\/span><span style=\"color: #D08770\">Scheduled<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">fixedRate<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">60000<\/span><span style=\"color: #ECEFF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">public<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">void<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">adjustPoolSize<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">currentActive<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">dataSource<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getHikariPoolMXBean<\/span><span style=\"color: #ECEFF4\">().<\/span><span style=\"color: #88C0D0\">getActiveConnections<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">maxPoolSize<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">dataSource<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">getMaximumPoolSize<\/span><span style=\"color: #ECEFF4\">()<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">        <\/span><span style=\"color: #616E88\">\/\/ \u6839\u636e\u5f53\u524d\u6d3b\u52a8\u8fde\u63a5\u6570\u8c03\u8282\u6700\u5927\u8fde\u63a5\u6c60\u5927\u5c0f<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">currentActive <\/span><span style=\"color: #81A1C1\">&gt;<\/span><span style=\"color: #D8DEE9FF\"> maxPoolSize <\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">int<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">newSize<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> maxPoolSize <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #D8DEE9\">dataSource<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">setMaximumPoolSize<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9FF\">newSize<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #D8DEE9\">System<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">out<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">println<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Increasing max pool size to: <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> newSize<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #ECEFF4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\u4ece\u4e0a\u9762\u7684\u7ed3\u679c\u4ee5\u53ca\u53cd\u5e94\u6765\u770b\uff0c\u5e76\u4e0d\u662f\u4e00\u8e74\u800c\u5c31\u7684\uff0c\u800c\u662f\u9700\u8981\u5faa\u5e8f\u6e10\u8fdb\u7684\u53bb\u4e00\u6b65\u4e00\u6b65\u7684\u6d4b\u8bd5\u5f97\u51fa\u7684\u7ed3\u8bba\uff0c\u5bf9\u4e8e\u5982\u4f55\u5feb\u901f\u63d2\u5165100w\u6761\u6570\u636e\u7684\u601d\u8003\u70b9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u591a\u7ebf\u7a0b\u6279\u91cf\u63d2\u5165\u7684\u524d\u63d0\u4e0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u4e86\u89e3\u5f53\u524d\u4e1a\u52a1\u573a\u666f\uff0c\u786e\u5b9a\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\uff0c\u5982\u679c\u662f\u5185\u5b58\u8ba1\u7b97\u5219\u5c06\u6838\u5fc3\u7ebf\u7a0b\u6570\u8c03\u6574\u4e3a\u4e0ecpu\u76f8\u540c\u6838\u5fc3\u6570\uff0c\u5982\u679c\u662f\u505a\u6570\u636e\u4f20\u8f93\u8bfb\u5199\u7684\u5219\u5c06\u6838\u5fc3\u7ebf\u7a0b\u6570\u8c03\u6574\u4e3acpu\u6838\u5fc3\u6570\u7684\u4e24\u500d\u6216\u4e24\u500d\u51cf\u4e00<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u6700\u5927\u7ebf\u7a0b\u6570\u5219\u6839\u636e\u4e1a\u52a1\u573a\u666f\u4e0e\u4efb\u52a1\u7684\u6570\u636e\u91cf\u4e00\u8fb9\u6d4b\u8bd5\u4e00\u8fb9\u8c03\u6574\uff08\u5982\u679c\u6700\u5927\u7ebf\u7a0b\u6570\u8bbe\u7f6e\u5f97\u8f83\u5c0f\uff0c\u610f\u5473\u7740\u7ebf\u7a0b\u6c60\u7684\u5e76\u53d1\u5904\u7406\u80fd\u529b\u6709\u9650\uff0c\u5f53\u4efb\u52a1\u6570\u91cf\u8d85\u8fc7\u6700\u5927\u7ebf\u7a0b\u6570\u65f6\uff0c\u65b0\u7684\u4efb\u52a1\u4f1a\u88ab\u653e\u5165\u961f\u5217\u4e2d\u7b49\u5f85\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u4efb\u52a1\u5904\u7406\u65f6\u95f4\u53d8\u957f\u3002\u5982\u679c\u6700\u5927\u7ebf\u7a0b\u6570\u8bbe\u7f6e\u5f97\u8f83\u5927\uff0c\u7ebf\u7a0b\u6c60\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u7684\u5e76\u53d1\u4efb\u52a1\uff0c\u4f46\u4e5f\u4f1a\u5360\u7528\u66f4\u591a\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u53ef\u80fd\u5bfc\u81f4\u7cfb\u7edf\u8d1f\u8f7d\u8fc7\u9ad8\uff0c\u751a\u81f3\u5f15\u53d1\u8d44\u6e90\u8017\u5c3d\u95ee\u9898\u3002\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u660e\u786e\u573a\u666f\u540e\u9009\u62e9\u5408\u9002\u7684\u963b\u585e\u961f\u5217\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u6027\u80fd\u5e73\u8861\u7684\u4efb\u52a1\u53ef\u4ee5\u9009\u62e9\u56fa\u5b9a\u5927\u5c0f\u7684\u963b\u585e\u961f\u5217\uff08<strong>ArrayBlockingQueue<\/strong>\uff09\uff0c\u6709\u7740\u6d77\u91cf\u6570\u636e\u7684\u4efb\u52a1\u5219\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u975e\u56fa\u5b9a\u5927\u5c0f\u7684\u963b\u585e\u961f\u5217\u63d0\u9ad8\u6027\u80fd\u4ee5\u53ca\u5229\u7528\u7387\uff08<strong>LinkedBlockingQueue<\/strong>\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4.\u5728\u4efb\u52a1\u6267\u884c\u9636\u6bb5\uff0c\u9700\u8981\u6839\u636e\u4e1a\u52a1\u6570\u636e\u6570\u91cf\u8c03\u6574\u5206\u6279\u63d2\u5165\u7684\u6570\u636e\u6761\u6570\uff0c\u5728mybatisplus\u7684\u6279\u91cf\u63d2\u5165\u65b9\u6cd5\u4e2d\u9ed8\u8ba4\u4e3a\u4e00\u62791000\u6761\u6570\u636e\uff0c\u6839\u636e\u4efb\u52a1\u6570\u636e\u91cf\u8c03\u6574\u81f3\u4e00\u4e2a\u5408\u9002\u7684\u5206\u6279\u6570\u91cf\u540c\u65f6\u8fd8\u9700\u8981\u8003\u8651\u6570\u636e\u6253\u5927\u5c0f\u5728\u7f51\u7edc\u4e2d\u4f20\u8f93\u7684\u5f71\u54cd\uff08\u662f\u5426\u56e0\u4e3a\u6570\u636e\u91cf\u8fc7\u5927\u5bfc\u81f4\u4f20\u8f93\u5931\u8d25\u6216\u8005\u6570\u636e\u4e22\u5931\u5bfc\u81f4\u63d2\u5165\u5931\u8d25\uff09\u7b49\u95ee\u9898<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5.\u5728\u4e0a\u8ff0\u95ee\u9898\u4e0a\u8fd8\u9700\u8981\u8003\u8651\u8fde\u63a5\u6c60\u7684\u914d\u7f6e\u662f\u5426\u914d\u7f6e\u5408\u7406\uff0c\u5f53\u8c03\u6574\u7ebf\u7a0b\u6c60\u4ee5\u53ca\u6279\u91cf\u63d2\u5165\u6761\u6570\u540e\u53d1\u73b0\u65e0\u6cd5\u518d\u63d0\u9ad8\u63d2\u5165\u6548\u7387\u65f6\u8003\u8651\u662f\u5426\u662f\u56e0\u4e3a\u6570\u636e\u5e93\u5bfc\u81f4\u7684\u74f6\u9888\u800c\u975e\u7ebf\u7a0b\u6c60\u4e0e\u5185\u5b58\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u4e3a\u9ad8\u6548\u7684\u52a8\u6001\u8c03\u6574\u65b9\u5f0f\uff0c\u6839\u636e\u670d\u52a1\u8fd0\u884c\u72b6\u6001\u52a8\u6001\u7684\u8c03\u6574\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\u7684\u662f\u5728\u4ee5\u4e0a\u8c03\u6574\u7684\u57fa\u7840\u4e0a\u8fd8\u9700\u8981\u7a0b\u5e8f\u6574\u4f53\u7684\u60c5\u51b5\uff0c\u4ee5\u907f\u514d\u5f53\u524d\u670d\u52a1\u4f7f\u7528\u8d44\u6e90\u8fc7\u591a\u3001\u8d44\u6e90\u5206\u914d\u4e0d\u5e73\u8861\u5bfc\u81f4\u7a0b\u5e8f\u51fa\u73b0\u4e0d\u7a33\u5b9a\u7684\u72b6\u51b5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u8fd9\u91cc\u653e\u51fa\u6240\u6709\u53c2\u8003\u5230\u7684\u6587\u7ae0\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u662f\u5728\u53c2\u8003\u548c\u501f\u9274\u4e2d\u5b8c\u6210\u7684\uff0c\u5982\u4f55\u5feb\u901f\u63d2\u5165100w\u6761\u6570\u636e\u7684\u601d\u8003\u4e5f\u662f\u7a81\u53d1\u5947\u60f3\u7684\uff0c\u5728\u5b9e\u8df5\u4e0e\u601d\u8003\u4e2d\u4e5f\u8ba9\u81ea\u5df1\u6709\u6240\u6536\u83b7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u53c2\u8003\u6587\u7ae0\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">LinkedBlockingQueue\u4e0eArrayBlockingQueue\u963b\u585e\u961f\u5217\u8be6\u89e3\uff1a<a href=\"https:\/\/www.cnblogs.com\/lenmom\/p\/12018347.html\">https:\/\/www.cnblogs.com\/lenmom\/p\/12018347.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ebf\u7a0b\u6c60\u7684\u6838\u5fc3\u7ebf\u7a0b\u6570\u548c\u6700\u5927\u7ebf\u7a0b\u6570\uff0c\u6709\u4ec0\u4e48\u533a\u522b\uff1f\uff1a<a href=\"https:\/\/blog.csdn.net\/qq_30939943\/article\/details\/141963740\">https:\/\/blog.csdn.net\/qq_30939943\/article\/details\/141963740<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MybatisPlus\u5b9e\u73b0\u771f\u6b63\u6279\u91cf\u63d2\u5165\uff1a<a href=\"https:\/\/blog.csdn.net\/m0_70871140\/article\/details\/142731767\">https:\/\/blog.csdn.net\/m0_70871140\/article\/details\/142731767<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u751f\u4ea7\u95ee\u9898\u4e4bCompletableFuture\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u8e29\u5751\uff0c\u8bf7\u52a1\u5fc5\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\uff1a<a href=\"https:\/\/www.cnblogs.com\/blackmlik\/p\/16098938.html\">https:\/\/www.cnblogs.com\/blackmlik\/p\/16098938.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">spring boot hikari \u8c03\u8bd5\u8fde\u63a5\u6c60\u6570\u91cf\uff1a<a href=\"https:\/\/blog.51cto.com\/u_16175520\/11678069\">https:\/\/blog.51cto.com\/u_16175520\/11678069<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u7ebf\u7a0b\u6279\u91cf\u63d2\u5165\u6570\u636e\u7684\u6d4b\u8bd5\u4e0e\u6027\u80fd\u5206\u6790\uff0c\u603b\u4f53\u6027\u80fd\u63d0\u534789.2%\uff08\u8bb2\u89e3\u7684\u5f88\u5168\u9762\u6570\u636e\u5bf9\u6bd4\u5f88\u6e05\u6670\uff09\uff1a<a href=\"https:\/\/blog.csdn.net\/m0_64422133\/article\/details\/141422842\">https:\/\/blog.csdn.net\/m0_64422133\/article\/details\/141422842<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u5148\u8bf4\u7ed3\u8bba\uff1a\u591a\u7ebf\u7a0b&gt;\u5355\u7ebf\u7a0b\uff0c\u6279\u91cf\u63d2\u5165&gt;\u5355\u72ec\u63d2\u5165 \u5982\u4f55\u5411\u6570\u636e\u5e93\u4e2d\u63d2\u5165\u6570\u636e\uff1f\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u6bd4\u5982\uff1a\u7f16\u5199 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.coffecat.cn\/index.php\/2024\/11\/30\/%e3%80%90%e5%9c%ba%e6%99%af%e5%ba%94%e7%94%a8%e8%ae%b0%e5%bd%95%e3%80%91-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%90%91mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e5%bf%ab%e9%80%9f%e6%8f%92%e5%85%a5100w\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u3010\u573a\u666f\u5e94\u7528\u8bb0\u5f55\u3011- \u5982\u4f55\u5b9e\u73b0\u5411mysql\u6570\u636e\u5e93\u4e2d\u5feb\u901f\u63d2\u5165100w\u6761\u6570\u636e\u201d<\/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":[19,35,1],"tags":[],"class_list":["post-1053","post","type-post","status-publish","format-standard","hentry","category-sql","category-35","category-uncategorized"],"views":1091,"_links":{"self":[{"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/posts\/1053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1053"}],"version-history":[{"count":63,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/posts\/1053\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/posts\/1053\/revisions\/1121"}],"wp:attachment":[{"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coffecat.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}