{"id":58775,"date":"2023-10-26T21:38:59","date_gmt":"2023-10-26T13:38:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=58775"},"modified":"2023-10-26T22:06:47","modified_gmt":"2023-10-26T14:06:47","slug":"java-%e5%86%85%e5%ad%98%e5%88%86%e9%85%8d%e7%9a%84%e9%97%ae%e9%a2%98%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/58775.html","title":{"rendered":"Java \u5185\u5b58\u5206\u914d\u7684\u95ee\u9898\u5982\u4f55\u89e3\u51b3"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>Java \u5185\u5b58\u5206\u914d\u4e0e\u7ba1\u7406\u662f\u5f00\u53d1\u4e2d\u7684\u5173\u952e\u8bae\u9898\uff0c\u786e\u4fdd\u7a33\u5b9a\u7684\u6027\u80fd\u548c\u907f\u514d\u8d44\u6e90\u6cc4\u9732\u3002\u672c\u6587\u5c06\u63a2\u8ba8\uff1a1.\u5185\u5b58\u5206\u914d\u7684\u57fa\u672c\u673a\u5236\uff1b2.\u5e38\u89c1\u7684\u5185\u5b58\u95ee\u9898\u53ca\u5176\u6210\u56e0\uff1b3.\u5982\u4f55\u8bca\u65ad\u4e0e\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1b4.\u63a8\u8350\u7684\u5de5\u5177\u4e0e\u5b9e\u8df5\uff1b5.\u5411\u524d\u770b\uff1a\u5982\u4f55\u9884\u9632\u672a\u6765\u7684\u5185\u5b58\u95ee\u9898\u3002\u5f00\u53d1\u8005\u9700\u6df1\u5165\u7406\u89e3Java\u5185\u5b58\u6a21\u578b\uff0c\u786e\u4fdd\u5e94\u7528\u8fd0\u884c\u7684\u9ad8\u6548\u4e0e\u7a33\u5b9a\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1.<\/strong><strong>\u5185\u5b58\u5206\u914d\u7684\u57fa\u672c\u673a\u5236<\/strong><\/h2>\n\n\n\n<p>Java\u5185\u5b58\u5927\u4f53\u4e0a\u53ef\u4ee5\u5206\u4e3a\u5806(heap)\u3001\u6808(stack)\u3001\u65b9\u6cd5\u533a\u548c\u76f4\u63a5\u5185\u5b58\u3002\u5176\u4e2d\uff0c\u5806\u662fJava\u8fd0\u884c\u65f6\u6570\u636e\u533a\u57df\u7684\u4e3b\u8981\u90e8\u5206\uff0c\u4e3b\u8981\u7528\u4e8e\u5b58\u653e\u5bf9\u8c61\u5b9e\u4f8b\u3002\u6bcf\u6b21\u5f53\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u5b9e\u4f8b\u65f6\uff0cJVM\u5c31\u4f1a\u5728\u5806\u4e0a\u4e3a\u5176\u5206\u914d\u5185\u5b58\u3002\u6808\u7528\u4e8e\u5b58\u653e\u57fa\u672c\u7c7b\u578b\u548c\u5bf9\u8c61\u5f15\u7528\u3002\u65b9\u6cd5\u533a\u4e3b\u8981\u5b58\u653e\u5df2\u88ab\u52a0\u8f7d\u7684\u7c7b\u4fe1\u606f\u3001\u5e38\u91cf\u3001\u9759\u6001\u53d8\u91cf\u7b49\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2.<\/strong><strong>\u5e38\u89c1\u7684\u5185\u5b58\u95ee\u9898\u53ca\u5176\u6210\u56e0<\/strong><\/h2>\n\n\n\n<p>\u5185\u5b58\u6cc4\u6f0f\uff1a\u662f\u6307\u5e94\u7528\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u6301\u7eed\u5360\u7528\u800c\u4e0d\u91ca\u653e\u7684\u5185\u5b58\uff0c\u53ef\u80fd\u5bfc\u81f4OutOfMemoryError\u3002<\/p>\n\n\n\n<p>\u8fc7\u65e9\u6216\u8fc7\u9891\u7e41\u7684GC\uff1a\u8fc7\u591a\u7684\u5c0f\u5bf9\u8c61\u4ea7\u751f\uff0c\u5bfc\u81f4\u9891\u7e41\u7684\u5783\u573e\u56de\u6536\uff0c\u5f71\u54cd\u5e94\u7528\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u5927\u5bf9\u8c61\u9891\u7e41\u5206\u914d\uff1a\u9700\u8981\u5927\u5757\u8fde\u7eed\u5185\u5b58\u7684\u5bf9\u8c61\u8fc7\u4e8e\u9891\u7e41\u5730\u521b\u5efa\u548c\u9500\u6bc1\uff0c\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3.<\/strong><strong>\u5982\u4f55\u8bca\u65ad\u4e0e\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898<\/strong><\/h2>\n\n\n\n<p>\u76d1\u63a7\u4e0e\u65e5\u5fd7\uff1a\u4f7f\u7528JVM\u63d0\u4f9b\u7684\u5de5\u5177\uff0c\u5982JVisualVM\u6216JMC\uff0c\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5b9a\u4f4d\u5f02\u5e38\u6ce2\u52a8\u3002<\/p>\n\n\n\n<p>\u5206\u6790heap dump\uff1a\u5728\u51fa\u73b0OutOfMemoryError\u65f6\uff0c\u53ef\u4ee5\u751f\u6210heap dump\u8fdb\u884c\u5206\u6790\uff0c\u786e\u5b9a\u5185\u5b58\u6cc4\u9732\u7684\u6839\u6e90\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.pingcode.com\/code-review\" target=\"_blank\">\u4ee3\u7801\u5ba1\u67e5<\/a>\uff1a\u5b9a\u671f\u8fdb\u884c\u4ee3\u7801\u5ba1\u67e5\uff0c\u786e\u4fdd\u6ca1\u6709\u4e0d\u5fc5\u8981\u7684\u5bf9\u8c61\u6301\u4e45\u5316\uff0c\u907f\u514d\u521b\u5efa\u8fc7\u5927\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4.<\/strong><strong>\u63a8\u8350\u7684\u5de5\u5177\u4e0e\u5b9e\u8df5<\/strong><\/h2>\n\n\n\n<p>\u4f7f\u7528JVisualVM\u6216MAT\uff1a\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5206\u6790\u5e94\u7528\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u67e5\u627e\u6cc4\u9732\u70b9\u3002<\/p>\n\n\n\n<p>\u907f\u514d\u4f7f\u7528Finalizers\u548cCleaners\uff1a\u5b83\u4eec\u53ef\u80fd\u5bfc\u81f4\u4e0d\u53ef\u9884\u89c1\u7684\u5ef6\u8fdf\u548c\u989d\u5916\u7684\u8d44\u6e90\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u8003\u8651\u4f7f\u7528\u5783\u573e\u56de\u6536\u5668\u7684\u914d\u7f6e\uff1a\u6839\u636e\u5e94\u7528\u7684\u7279\u70b9\uff0c\u9009\u62e9\u5408\u9002\u7684\u5783\u573e\u56de\u6536\u7b56\u7565\uff0c\u5982G1\u3001CMS\u6216Parallel GC\u3002<\/p>\n\n\n\n<p>\u5411\u524d\u770b\uff1a\u5982\u4f55\u9884\u9632\u672a\u6765\u7684\u5185\u5b58\u95ee\u9898<\/p>\n\n\n\n<p>\u6301\u7eed\u6559\u80b2\uff1a\u8ba9\u5f00\u53d1\u56e2\u961f\u4e86\u89e3Java\u7684\u5185\u5b58\u6a21\u578b\u548c\u5e38\u89c1\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u81ea\u52a8\u5316\u6d4b\u8bd5\uff1a\u5b9a\u671f\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5\u548c\u6027\u80fd\u6d4b\u8bd5\uff0c\u786e\u4fdd\u5e94\u7528\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u4f9d\u7136\u7a33\u5b9a\u3002<\/p>\n\n\n\n<p>\u6846\u67b6\u4e0e\u5e93\u9009\u62e9\uff1a\u907f\u514d\u4f7f\u7528\u5df2\u77e5\u6709\u5185\u5b58\u95ee\u9898\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u9009\u62e9\u90a3\u4e9b\u7ecf\u8fc7\u4e25\u683c\u6d4b\u8bd5\u548c\u793e\u533a\u9a8c\u8bc1\u7684\u5e93\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"484\" height=\"300\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u6dfb\u52a0\u6807\u9898-10-1.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-58879\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u7b54<\/strong><\/h2>\n\n\n\n<p><strong>1.Java <\/strong><strong>\u7684\u5185\u5b58\u6a21\u578b\u662f\u5982\u4f55\u7ec4\u6210\u7684\uff1f<\/strong><\/p>\n\n\n\n<p>Java \u7684\u5185\u5b58\u6a21\u578b\u4e3b\u8981\u7531\u5806\uff08Heap\uff09\u3001\u6808\uff08Stack\uff09\u3001\u65b9\u6cd5\u533a\uff08Method Area\uff09\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668\uff08Program Counter Register\uff09\u548c\u672c\u5730\u65b9\u6cd5\u6808\uff08Native Method Stack\uff09\u7ec4\u6210\u3002\u5176\u4e2d\uff0c\u5806\u662f\u7528\u4e8e\u5b58\u653e\u5bf9\u8c61\u5b9e\u4f8b\u7684\uff0c\u6808\u7528\u4e8e\u5b58\u653e\u5c40\u90e8\u53d8\u91cf\u3001\u64cd\u4f5c\u6570\u6808\u7b49\uff0c\u65b9\u6cd5\u533a\u5b58\u653e\u7c7b\u4fe1\u606f\u3001\u5e38\u91cf\u3001\u9759\u6001\u53d8\u91cf\u7b49\u3002<\/p>\n\n\n\n<p><strong>2.Java <\/strong><strong>\u4e2d\u5185\u5b58\u6cc4\u9732\u548c\u5185\u5b58\u6ea2\u51fa\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n\n\n\n<p>\u5185\u5b58\u6cc4\u9732\u662f\u6307\u7a0b\u5e8f\u5728\u7533\u8bf7\u5185\u5b58\u540e\uff0c\u65e0\u6cd5\u91ca\u653e\u5df2\u7533\u8bf7\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u5373\u4f7f\u8be5\u5185\u5b58\u5df2\u7ecf\u4e0d\u518d\u4f7f\u7528\u3002\u4e45\u800c\u4e45\u4e4b\uff0c\u8fd9\u4e9b\u672a\u88ab\u91ca\u653e\u7684\u5185\u5b58\u4f1a\u7d2f\u79ef\uff0c\u53ef\u80fd\u5bfc\u81f4\u7cfb\u7edf\u8d44\u6e90\u8017\u5c3d\u3002\u5185\u5b58\u6ea2\u51fa\u5219\u662f\u6307\u5f53\u7a0b\u5e8f\u7533\u8bf7\u5185\u5b58\u65f6\uff0c\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\u4f9b\u5176\u4f7f\u7528\uff0c\u5bfc\u81f4\u51fa\u73b0\u6ea2\u51fa\u9519\u8bef\u3002<\/p>\n\n\n\n<p><strong>3.<\/strong><strong>\u5982\u4f55\u68c0\u6d4b\u548c\u5206\u6790Java\u5e94\u7528\u7684\u5185\u5b58\u95ee\u9898\uff1f<\/strong><\/p>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u4e13\u4e1a\u7684\u5de5\u5177\u5982JVisualVM\u3001MAT (Memory Analyzer Tool)\u3001JProfiler\u7b49\u6765\u68c0\u6d4b\u548c\u5206\u6790Java\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5b9a\u4f4d\u5230\u5177\u4f53\u7684\u5bf9\u8c61\u3001\u7c7b\u6216\u7ebf\u7a0b\uff0c\u67e5\u627e\u53ef\u80fd\u7684\u5185\u5b58\u6cc4\u9732\u6216\u8005\u8fc7\u5ea6\u6d88\u8017\u7684\u5730\u65b9\u3002<\/p>\n\n\n\n<p><strong>4.Java <\/strong><strong>\u4e2d\u5783\u573e\u56de\u6536\uff08GC\uff09\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f<\/strong><\/p>\n\n\n\n<p>Java\u4e2d\u7684\u5783\u573e\u56de\u6536\u673a\u5236\u662f\u81ea\u52a8\u7684\u3002\u5176\u4e3b\u8981\u57fa\u4e8e\u201c\u6807\u8bb0-\u6e05\u9664-\u6574\u7406\u201d\u7b97\u6cd5\u3002\u9996\u5148\uff0c\u5b83\u6807\u8bb0\u51fa\u6240\u6709\u4e0d\u518d\u4f7f\u7528\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u6e05\u9664\u8fd9\u4e9b\u5bf9\u8c61\u6240\u5360\u7528\u7684\u5185\u5b58\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u63d0\u9ad8\u5185\u5b58\u4f7f\u7528\u6548\u7387\uff0c\u5b83\u8fd8\u53ef\u80fd\u4f1a\u8fdb\u884c\u5185\u5b58\u6574\u7406\uff0c\u5c06\u5b58\u6d3b\u7684\u5bf9\u8c61\u79fb\u5230\u5806\u7684\u4e00\u7aef\u3002<\/p>\n\n\n\n<p><strong>5.<\/strong><strong>\u4ec0\u4e48\u662fJava\u7684\u5185\u5b58\u6cc4\u9732\uff0c\u5982\u4f55\u907f\u514d\uff1f<\/strong><\/p>\n\n\n\n<p>Java\u7684\u5185\u5b58\u6cc4\u9732\u662f\u6307\u67d0\u4e9b\u5bf9\u8c61\u4e0d\u518d\u4f7f\u7528\uff0c\u4f46\u5783\u573e\u56de\u6536\u5668\u65e0\u6cd5\u8bc6\u522b\u5e76\u56de\u6536\u5b83\u4eec\uff0c\u5bfc\u81f4\u8fd9\u90e8\u5206\u5185\u5b58\u65e0\u6cd5\u88ab\u91cd\u65b0\u5229\u7528\u3002\u907f\u514d\u5185\u5b58\u6cc4\u9732\u7684\u65b9\u6cd5\u6709\uff1a\u786e\u4fdd\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406\u5f97\u5f53\uff0c\u907f\u514d\u957f\u65f6\u95f4\u6301\u6709\u4e0d\u518d\u9700\u8981\u7684\u5bf9\u8c61\u5f15\u7528\uff1b\u4f7f\u7528\u5f31\u5f15\u7528\u6216\u8f6f\u5f15\u7528\uff1b\u5b9a\u671f\u5730\u8fdb\u884c\u4ee3\u7801\u5ba1\u67e5\uff0c\u4f7f\u7528\u5185\u5b58\u5206\u6790\u5de5\u5177\u68c0\u67e5\u53ef\u80fd\u7684\u5185\u5b58\u6cc4\u9732\u70b9\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Java \u5185\u5b58\u5206\u914d\u4e0e\u7ba1\u7406\u662f\u5f00\u53d1\u4e2d\u7684\u5173\u952e\u8bae\u9898\uff0c\u786e\u4fdd\u7a33\u5b9a\u7684\u6027\u80fd\u548c\u907f\u514d\u8d44\u6e90\u6cc4\u9732\u3002\u672c\u6587\u5c06\u63a2\u8ba8\uff1a1.\u5185\u5b58\u5206\u914d\u7684\u57fa\u672c\u673a\u5236\uff1b [&hellip;]","protected":false},"author":5,"featured_media":58879,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/58775"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=58775"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/58775\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/58879"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=58775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=58775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=58775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}