{"id":46924,"date":"2024-12-02T11:10:42","date_gmt":"2024-12-02T03:10:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46924\/"},"modified":"2024-12-02T11:10:42","modified_gmt":"2024-12-02T03:10:42","slug":"%e6%8f%90%e5%8d%87java%e5%87%bd%e6%95%b0%e5%86%85%e5%ad%98%e6%95%88%e7%8e%87%e7%9a%84%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46924\/","title":{"rendered":"\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p>\u901a\u8fc7\u542f\u7528 G1 \u5783\u573e\u6536\u96c6\u5668 (G1GC)\uff0c\u5e76\u8c03\u6574\u8bbe\u7f6e\uff08\u5982\u533a\u57df\u5927\u5c0f\u3001\u4fdd\u7559\u767e\u5206\u6bd4\u3001\u6700\u5927 GC \u6682\u505c\u65f6\u95f4\uff09\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\uff0c\u53ef\u4ee5\u4f18\u5316 Java \u51fd\u6570\u7684\u5185\u5b58\u6548\u7387\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u542f\u7528 G1GC\uff1b2. \u8c03\u6574 G1GC \u8bbe\u7f6e\uff1b3. \u76d1\u89c6 GC \u65e5\u5fd7\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u4f18\u5316\u65e5\u5fd7\u5904\u7406\u51fd\u6570\uff0c\u901a\u8fc7\u542f\u7528 G1GC\u3001\u8c03\u6574\u533a\u57df\u5927\u5c0f\u3001\u4fdd\u7559\u767e\u5206\u6bd4\u3001\u6700\u5927 GC \u6682\u505c\u65f6\u95f4\uff0c\u663e\u8457\u51cf\u5c11\u4e86 GC \u6682\u505c\u65f6\u95f4\uff0c\u63d0\u5347\u4e86\u51fd\u6570\u6027\u80fd\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729936162671cbb22b1828.jpg\" class=\"aligncenter\" title=\"\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177\u63d2\u56fe\" alt=\"\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5229\u7528 G1GC \u63d0\u5347 Java \u51fd\u6570\u5185\u5b58\u6548\u7387<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u5185\u5b58\u6d88\u8017\u5728 Java \u5e94\u7528\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u51fd\u6570\u3002\u5982\u679c\u6ca1\u6709\u6709\u6548\u7684\u5185\u5b58\u7ba1\u7406\u7b56\u7565\uff0c\u5219\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u4e0b\u964d\u751a\u81f3\u7cfb\u7edf\u5d29\u6e83\u3002\u672c\u6587\u63a2\u8ba8\u4e86\u4e00\u79cd\u5229\u7528 G1 \u5783\u573e\u6536\u96c6\u5668 (G1GC) \u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5b9e\u7528\u65b9\u6cd5\u3002<\/p>\n<p><strong>G1GC \u7b80\u4ecb<\/strong><\/p>\n<p>G1GC \u662f OpenJDK 9 \u4e2d\u5f15\u5165\u7684\u5783\u573e\u6536\u96c6\u5668\uff0c\u5b83\u7ed3\u5408\u4e86\u541e\u5410\u91cf\u4f18\u5148\u548c\u4f4e\u5ef6\u8fdf\u4f18\u5148\u5783\u573e\u6536\u96c6\u5668\u7684\u4f18\u70b9\u3002G1GC \u5c06\u5806\u5185\u5b58\u5206\u4e3a\u591a\u4e2a\u79f0\u4e3a\u300c\u533a\u57df\u300d\u7684\u5757\uff0c\u5e76\u9488\u5bf9\u6bcf\u4e2a\u533a\u57df\u4f7f\u7528\u5e76\u53d1\u6807\u8bb0\u6e05\u9664\u7b97\u6cd5\u3002<\/p>\n<p><strong>\u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387<\/strong><\/p>\n<p>\u4ee5\u4e0b\u6b65\u9aa4\u8bf4\u660e\u4e86\u5982\u4f55\u4f7f\u7528 G1GC \u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387\uff1a<\/p>\n<p><strong>1. \u542f\u7528 G1GC<\/strong><\/p>\n<p>\u5728 JVM \u542f\u52a8\u53c2\u6570\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u9009\u9879\u4ee5\u542f\u7528 G1GC\uff1a<\/p>\n<pre>-XX:+UseG1GC<\/pre>\n<p><strong>2. \u8c03\u6574 G1GC \u8bbe\u7f6e<\/strong><\/p>\n<p>\u4ee5\u4e0b\u8bbe\u7f6e\u53ef\u4ee5\u8fdb\u4e00\u6b65\u8c03\u6574 G1GC \u7684\u884c\u4e3a\uff1a<\/p>\n<ul>\n<li><strong>-XX:G1HeapRegionSize=n<\/strong>\uff1a\u8bbe\u7f6e\u6bcf\u4e2a G1 \u533a\u57df\u7684\u5927\u5c0f\uff08\u4ee5 MB \u4e3a\u5355\u4f4d\uff09\u3002\u8f83\u5c0f\u7684\u533a\u57df\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002<\/li>\n<li><strong>-XX:G1ReservePercent=n<\/strong>\uff1a\u4fdd\u7559\u4e00\u5b9a\u6bd4\u4f8b\u7684\u5806\u5185\u5b58\u4ee5\u5e94\u5bf9\u5cf0\u503c\u8d1f\u8f7d\u3002<\/li>\n<li><strong>-XX:MaxGCPauseMillis=n<\/strong>\uff1a\u8bbe\u7f6e\u6700\u5927 GC \u6682\u505c\u65f6\u95f4\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/li>\n<\/ul>\n<p><strong>3. \u76d1\u89c6 GC \u65e5\u5fd7<\/strong><\/p>\n<p>\u4f7f\u7528 <code>jstat -gcutil<\/code> \u547d\u4ee4\u6216 JVM \u76d1\u89c6\u5de5\u5177\uff08\u5982 JConsole\uff09\u76d1\u89c6 GC \u6d3b\u52a8\u3002\u8bc6\u522b\u9891\u7e41\u6216\u957f\u65f6\u95f4 GC \u6682\u505c\uff0c\u5e76\u6839\u636e\u9700\u8981\u8c03\u6574 G1GC \u8bbe\u7f6e\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u4e00\u4e2a Java \u51fd\u6570\u5904\u7406\u5927\u91cf\u65e5\u5fd7\u6570\u636e\uff0c\u5e76\u4e14\u7531\u4e8e GC \u6682\u505c\u800c\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<ul>\n<li>\u542f\u7528 G1GC \u5e76\u8c03\u6574 <code>G1HeapRegionSize<\/code> \u4e3a 16MB\u3002<\/li>\n<li>\u5c06 <code>G1ReservePercent<\/code> \u8bbe\u7f6e\u4e3a 20%\uff0c\u4ee5\u5e94\u5bf9\u5cf0\u503c\u8d1f\u8f7d\u3002<\/li>\n<li>\u5c06 <code>MaxGCPauseMillis<\/code> \u8bbe\u7f6e\u4e3a 200 \u6beb\u79d2\uff0c\u4ee5\u786e\u4fdd\u77ed\u7684 GC \u6682\u505c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u7ecf\u8fc7\u8fd9\u4e9b\u4f18\u5316\u540e\uff0cGC \u6682\u505c\u65f6\u95f4\u663e\u8457\u51cf\u5c11\uff0c\u51fd\u6570\u6027\u80fd\u5927\u5e45\u63d0\u9ad8\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u5229\u7528 G1GC\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6709\u6548\u5730\u4f18\u5316 Java \u51fd\u6570\u7684\u5185\u5b58\u6548\u7387\uff0c\u4ece\u800c\u51cf\u5c11 GC \u6682\u505c\u5e76\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002\u672c\u6587\u63d0\u4f9b\u7684\u5b9e\u7528\u65b9\u6cd5\u4e3a\u5185\u5b58\u7ba1\u7406\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ef\u91cd\u590d\u7684\u7b56\u7565\uff0c\u5e2e\u52a9\u5e94\u7528\u7a0b\u5e8f\u5e73\u7a33\u8fd0\u884c\u5e76\u5e94\u5bf9\u8981\u6c42\u4e25\u683c\u7684\u8d1f\u8f7d\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177 \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u63d0\u5347Java\u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5de5\u5177\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 \u901a\u8fc7\u542f\u7528 G1 \u5783\u573e\u6536\u96c6\u5668 (G1GC)\uff0c\u5e76\u8c03\u6574\u8bbe\u7f6e\uff08\u5982\u533a\u57df\u5927\u5c0f\u3001\u4fdd\u7559\u767e\u5206\u6bd4\u3001\u6700\u5927 GC \u6682\u505c\u65f6\u95f4\uff09\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\uff0c\u53ef\u4ee5\u4f18\u5316 Java \u51fd\u6570\u7684\u5185\u5b58\u6548\u7387\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u542f\u7528 G1GC\uff1b2. \u8c03\u6574 G1GC \u8bbe\u7f6e\uff1b3. \u76d1\u89c6 GC \u65e5\u5fd7\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u4f18\u5316\u65e5\u5fd7\u5904\u7406\u51fd\u6570\uff0c\u901a\u8fc7\u542f\u7528 G1GC\u3001\u8c03\u6574\u533a\u57df\u5927\u5c0f\u3001\u4fdd\u7559\u767e\u5206\u6bd4\u3001\u6700\u5927 GC \u6682\u505c\u65f6\u95f4\uff0c\u663e\u8457\u51cf\u5c11\u4e86 GC \u6682\u505c\u65f6\u95f4\uff0c\u63d0\u5347\u4e86\u51fd\u6570\u6027\u80fd\u3002 \u5229\u7528 G1GC \u63d0\u5347 Java \u51fd\u6570\u5185\u5b58\u6548\u7387 \u5f15\u8a00 \u5185\u5b58\u6d88\u8017\u5728 Java \u5e94\u7528\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u51fd\u6570\u3002\u5982\u679c\u6ca1\u6709\u6709\u6548\u7684\u5185\u5b58\u7ba1\u7406\u7b56\u7565\uff0c\u5219\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u4e0b\u964d\u751a\u81f3\u7cfb\u7edf\u5d29\u6e83\u3002\u672c\u6587\u63a2\u8ba8\u4e86\u4e00\u79cd\u5229\u7528 G1 \u5783\u573e\u6536\u96c6\u5668 (G1GC) \u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387\u7684\u5b9e\u7528\u65b9\u6cd5\u3002 G1GC \u7b80\u4ecb G1GC \u662f OpenJDK 9 \u4e2d\u5f15\u5165\u7684\u5783\u573e\u6536\u96c6\u5668\uff0c\u5b83\u7ed3\u5408\u4e86\u541e\u5410\u91cf\u4f18\u5148\u548c\u4f4e\u5ef6\u8fdf\u4f18\u5148\u5783\u573e\u6536\u96c6\u5668\u7684\u4f18\u70b9\u3002G1GC \u5c06\u5806\u5185\u5b58\u5206\u4e3a\u591a\u4e2a\u79f0\u4e3a\u300c\u533a\u57df\u300d\u7684\u5757\uff0c\u5e76\u9488\u5bf9\u6bcf\u4e2a\u533a\u57df\u4f7f\u7528\u5e76\u53d1\u6807\u8bb0\u6e05\u9664\u7b97\u6cd5\u3002 \u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387 \u4ee5\u4e0b\u6b65\u9aa4\u8bf4\u660e\u4e86\u5982\u4f55\u4f7f\u7528 G1GC \u4f18\u5316 Java \u51fd\u6570\u5185\u5b58\u6548\u7387\uff1a 1. [&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-46924","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46924","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=46924"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46924\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}