{"id":200243,"date":"2025-05-06T10:22:09","date_gmt":"2025-05-06T02:22:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200243\/"},"modified":"2025-05-06T10:22:09","modified_gmt":"2025-05-06T02:22:09","slug":"springbootmybatismysql-%e6%89%b9%e9%87%8f%e6%96%b0%e5%a2%9e%e6%95%b0%e6%8d%ae%e6%97%b6%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8doom%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200243\/","title":{"rendered":"SpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>SpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f<\/h1>\n<p>\u76ee\u524d\u4e3b\u673a\u5b9d\u8d1d\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/173025203767218d05c0aee.jpg\" class=\"aligncenter\"><\/p>\n<h2>springboot+mybatis+mysql\u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\uff0c\u907f\u514d\u6570\u636e\u8fc7\u5927\u5f15\u53d1oom<\/h2>\n<p>\u5728\u6279\u91cf\u65b0\u589e\u6570\u636e\u5230\u6570\u636e\u5e93\u65f6\uff0c\u7531\u4e8e\u6570\u636e\u91cf\u4e0d\u786e\u5b9a\uff0c\u53ef\u80fd\u5bfc\u81f4\u51fa\u73b0oom\uff08\u5185\u5b58\u6ea2\u51fa\uff09\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u907f\u514d\u8fd9\u79cd\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848\uff1a\u5206\u6279\u4fdd\u5b58<\/h3>\n<p><strong>1. \u4ee3\u7801\u4f18\u5316<\/strong><\/p>\n<p>\u63d0\u4f9b\u7684\u4ee3\u7801\u5728\u5904\u7406\u6700\u540e\u4e00\u6bb5\u6570\u636e\u65f6\uff0c\u9700\u8981\u5355\u72ec\u5904\u7406\u3002\u53ef\u4ee5\u5bf9\u4ee3\u7801\u8fdb\u884c\u5982\u4e0b\u4f18\u5316\uff1a<\/p>\n<pre>public void insert(list&lt;user&gt; list) {\n    int count = 10000; \/\/ \u6bcf\u6b21\u5904\u7406\u6570\u636e\u91cf\n    int pagesize = list.size() % count == 0 ? list.size() \/ count : list.size() \/ count + 1;\n    for(int i=0; i&amp;lt;pagesize; i++){\n        list&amp;lt;integer&amp;gt; list1 = list.sublist(i * count, (i + 1) * count &lt;= list.size() ? (i + 1) * count : list.size());\n        usermapper.insert(list1); \/\/ \u6bcf\u6b21\u4f20count\u6570\u91cf\u7684\u6570\u636e\u5230mapper\u65b9\u6cd5\u91cc\n    }\n}<\/pre>\n<p><strong>2. \u66f4\u4f18\u65b9\u6cd5\uff1a\u6279\u91cf\u66f4\u65b0sql<\/strong><\/p>\n<p>\u9664\u4e86\u5206\u6279\u4fdd\u5b58\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6279\u91cf\u66f4\u65b0sql\u6765\u66f4\u6709\u6548\u5730\u63d2\u5165\u6570\u636e\u3002 <\/p>\n<pre>INSERT INTO user (name, age) VALUES\n(?, ?),\n(?, ?),\n...\n(?, ?);<\/pre>\n<p>\u901a\u8fc7\u5c06\u591a\u6761insert\u8bed\u53e5\u7ec4\u5408\u6210\u5355\u4e2a\u6279\u91cf\u8bed\u53e5\uff0c\u53ef\u4ee5\u663e\u7740\u51cf\u5c11\u6570\u636e\u5e93\u4ea4\u4e92\u6b21\u6570\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002 <\/p>\n<p>\u4e0d\u8981\u8fc7\u5ea6\u89c4\u8303\u6570\u636e\u91cf\u7684\u5927\u5c0f\uff0c\u5e94\u8be5\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u60c5\u51b5\u548c\u7cfb\u7edf\u8d44\u6e90\u60c5\u51b5\u6765\u51b3\u5b9a\u3002\u540c\u65f6\uff0c\u4e5f\u8981\u6ce8\u610f\u76d1\u63a7\u7cfb\u7edf\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u907f\u514d\u8d85\u51fa\u9650\u5236\u3002 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aSpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\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-200243","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200243","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=200243"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200243\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}