{"id":200957,"date":"2025-05-06T14:54:30","date_gmt":"2025-05-06T06:54:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200957\/"},"modified":"2025-05-06T14:54:30","modified_gmt":"2025-05-06T06:54:30","slug":"springbootmybatismysql-%e6%89%b9%e9%87%8f%e6%96%b0%e5%a2%9e%e6%95%b0%e6%8d%ae%ef%bc%8c%e5%a6%82%e4%bd%95%e9%ab%98%e6%95%88%e9%81%bf%e5%85%8doom%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200957\/","title":{"rendered":"SpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>SpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6570\u636e\u5e93\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aSpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/1732331742674148de8fcc7.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>springboot+mybatis+mysql\u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514doom\uff1f<\/strong><\/p>\n<p>\u5728\u6279\u91cf\u63d2\u5165\u6570\u636e\u5230 mysql \u65f6\uff0c\u9700\u8981\u786e\u4fdd\u6570\u636e\u91cf\u4e0d\u4f1a\u8fc7\u5927\u4ee5\u907f\u514d\u51fa\u73b0 oom \u5f02\u5e38\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\u7684\u5efa\u8bae\uff1a<\/p>\n<ol>\n<li><strong>\u89c4\u8303\u6570\u636e\u91cf<\/strong><\/li>\n<\/ol>\n<p>\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u65f6\uff0c\u6700\u597d\u7531\u4e1a\u52a1\u5c42\u8fdb\u884c\u7ea6\u675f\uff0c\u9650\u5236\u6570\u636e\u91cf\u5728\u4e00\u4e2a\u5408\u7406\u8303\u56f4\u5185\uff0c\u907f\u514d\u4e00\u6b21\u6027\u4f20\u8f93\u8fc7\u91cf\u6570\u636e\u3002<\/p>\n<ol>\n<li><strong>\u5206\u6279\u4fdd\u5b58<\/strong><\/li>\n<\/ol>\n<p>\u4f60\u7684\u5206\u6279\u4fdd\u5b58\u601d\u8def\u662f\u6b63\u786e\u7684\u3002\u5bf9\u4e8e\u5927\u6279\u91cf\u6570\u636e\uff0c\u53ef\u4ee5\u5c06\u5176\u6309\u4e00\u5b9a\u5927\u5c0f\u5206\u6279\u63d2\u5165\u6570\u636e\u5e93\u3002\u4f60\u7684\u4ee3\u7801\u4e2d\u6bcf 10000 \u6761\u6570\u636e\u5206\u6279\u63d2\u5165\uff0c\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574\u8fd9\u4e2a\u6279\u6b21\u5927\u5c0f\u3002<\/p>\n<ol>\n<li><strong>\u4f18\u5316\u4ee3\u7801<\/strong><\/li>\n<\/ol>\n<p>\u4f60\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5bf9\u8c61\u521b\u5efa\uff1a<\/p>\n<pre>public void insert(List&lt;User&gt; list) {\n    int count = 10000; \/\/ \u8fd9\u91cc\u6682\u4e0d\u8003\u8651\u6570\u636e\u91cf\u5c0f\u4e8e10000\u7684\u60c5\u51b5\n    int max = list.size();\n    while (max &gt; 0) {\n        int temp = Math.min(count, max);\n        List&lt;User&gt; subList = list.subList(max - temp, max);\n        userMapper.insert(subList);\n        max -= temp;\n    }\n}<\/pre>\n<p>\u5728\u4f18\u5316\u540e\u7684\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528 while \u5faa\u73af\u907f\u514d\u4e86\u4e0d\u5fc5\u8981\u7684 for \u5faa\u73af\u5bf9\u8c61\u521b\u5efa\uff0c\u5e76\u4e14\u4f7f\u7528 math.min \u786e\u4fdd\u6bcf\u6b21\u5206\u6279\u63d2\u5165\u7684\u6570\u636e\u5927\u5c0f\u4e0d\u8d85\u8fc7 count\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aSpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot+Mybat&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200957","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200957"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200957\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}