{"id":6996,"date":"2024-11-14T11:19:53","date_gmt":"2024-11-14T03:19:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6996\/"},"modified":"2024-11-14T11:19:53","modified_gmt":"2024-11-14T03:19:53","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:\/\/fwq.ai\/blog\/6996\/","title":{"rendered":"SpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173026210765245.jpg\" class=\"aligncenter\" title=\"SpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f\u63d2\u56fe\" alt=\"SpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>springboot+mybatis+\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fSpringBoot+Mybatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514dOOM\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>springboot+mybatis+\u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\uff0c\u5982\u4f55\u9ad8\u6548\u907f\u514doom\uff1f \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 \u89c4\u8303\u6570\u636e\u91cf \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 \u5206\u6279\u4fdd\u5b58 \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 \u4f18\u5316\u4ee3\u7801 \u4f60\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5bf9\u8c61\u521b\u5efa\uff1a public void insert(List&lt;User&gt; list) { int count = 10000; \/\/ \u8fd9\u91cc\u6682\u4e0d\u8003\u8651\u6570\u636e\u91cf\u5c0f\u4e8e10000\u7684\u60c5\u51b5 int max = list.size(); while (max &gt; 0) { int temp = Math.min(count, max); List&lt;User&gt; subList = list.subList(max &#8211; temp, max); userMapper.insert(subList); max -= temp; } } \u767b\u5f55\u540e\u590d\u5236 \u5728\u4f18\u5316\u540e\u7684\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528 while [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6996","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6996"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6996\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}