{"id":36906,"date":"2024-11-26T10:21:36","date_gmt":"2024-11-26T02:21:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36906\/"},"modified":"2024-11-26T10:21:36","modified_gmt":"2024-11-26T02:21:36","slug":"java%e5%a4%a7%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%8a%a0%e7%82%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36906\/","title":{"rendered":"java\u5927\u6570\u7ec4\u600e\u4e48\u52a0\u70b9"},"content":{"rendered":"<blockquote><p>\n  \u4e3a java \u4e2d\u7684\u5927\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 -xmx \u53c2\u6570\u8bbe\u7f6e jvm \u7684\u6700\u5927\u5806\u5185\u5b58\u5927\u5c0f\u3002\u4f7f\u7528 arraylist\uff0c\u8fd9\u662f\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u957f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111221213067292.jpg\" class=\"aligncenter\" title=\"java\u5927\u6570\u7ec4\u600e\u4e48\u52a0\u70b9\u63d2\u56fe\" alt=\"java\u5927\u6570\u7ec4\u600e\u4e48\u52a0\u70b9\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4e3a Java \u4e2d\u7684\u5927\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58<\/strong><\/p>\n<p>\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\uff0cJava \u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u56e0\u5185\u5b58\u4e0d\u8db3\u9519\u8bef\u800c\u5d29\u6e83\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u6570\u7ec4\u5206\u914d\u66f4\u591a\u7684\u5185\u5b58\u3002\u4e0b\u9762\u4ecb\u7ecd\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 -Xmx \u53c2\u6570<\/strong><\/p>\n<p>-Xmx \u53c2\u6570\u8bbe\u7f6e Java \u865a\u62df\u673a\uff08JVM\uff09\u7684\u6700\u5927\u5806\u5185\u5b58\u5927\u5c0f\u3002\u901a\u8fc7\u589e\u52a0\u6b64\u503c\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58\u3002\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>java -Xmx4g Main<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u4e3a JVM \u5206\u914d 4GB \u7684\u6700\u5927\u5806\u5185\u5b58\u3002<\/p>\n<p><strong>2. \u4f7f\u7528 ArrayList<\/strong><\/p>\n<p>\u5982\u679c\u6570\u7ec4\u5927\u5c0f\u672a\u77e5\u6216\u53ef\u80fd\u6539\u53d8\uff0c\u53ef\u4ee5\u4f7f\u7528 ArrayList\u3002ArrayList \u662f\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u957f\u4ee5\u5bb9\u7eb3\u65b0\u5143\u7d20\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;&gt;();\nfor (int i = 0; i &lt; 1000000; i++) {\n    numbers.add(i);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b 100 \u4e07\u4e2a\u6574\u6570\u7684 ArrayList\uff0c\u5373\u4f7f\u6570\u7ec4\u5927\u5c0f\u6ca1\u6709\u4e8b\u5148\u6307\u5b9a\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5206\u914d\u66f4\u591a\u5185\u5b58\u4f1a\u589e\u52a0\u5e94\u7528\u7a0b\u5e8f\u7684\u5360\u7528\u7a7a\u95f4\u3002<\/li>\n<li>\u8fc7\u591a\u5206\u914d\u5185\u5b58\u4f1a\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/li>\n<li>\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\u5904\u7406\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u5927\u6570\u7ec4\u600e\u4e48\u52a0\u70b9\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a java \u4e2d\u7684\u5927\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 -xmx \u53c2\u6570\u8bbe\u7f6e jvm \u7684\u6700\u5927\u5806\u5185\u5b58\u5927\u5c0f\u3002\u4f7f\u7528 arraylist\uff0c\u8fd9\u662f\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u957f\u3002 \u5982\u4f55\u4e3a Java \u4e2d\u7684\u5927\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58 \u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\uff0cJava \u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u56e0\u5185\u5b58\u4e0d\u8db3\u9519\u8bef\u800c\u5d29\u6e83\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u6570\u7ec4\u5206\u914d\u66f4\u591a\u7684\u5185\u5b58\u3002\u4e0b\u9762\u4ecb\u7ecd\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a 1. \u4f7f\u7528 -Xmx \u53c2\u6570 -Xmx \u53c2\u6570\u8bbe\u7f6e Java \u865a\u62df\u673a\uff08JVM\uff09\u7684\u6700\u5927\u5806\u5185\u5b58\u5927\u5c0f\u3002\u901a\u8fc7\u589e\u52a0\u6b64\u503c\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a\u6570\u7ec4\u5206\u914d\u66f4\u591a\u5185\u5b58\u3002\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b java -Xmx4g Main \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u4e3a JVM \u5206\u914d 4GB \u7684\u6700\u5927\u5806\u5185\u5b58\u3002 2. \u4f7f\u7528 ArrayList \u5982\u679c\u6570\u7ec4\u5927\u5c0f\u672a\u77e5\u6216\u53ef\u80fd\u6539\u53d8\uff0c\u53ef\u4ee5\u4f7f\u7528 ArrayList\u3002ArrayList \u662f\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u957f\u4ee5\u5bb9\u7eb3\u65b0\u5143\u7d20\u3002\u4f8b\u5982\uff1a ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;&gt;(); for (int i = 0; i &lt; 1000000; i++) { numbers.add(i); } \u767b\u5f55\u540e\u590d\u5236 [&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-36906","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36906","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=36906"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36906\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}