{"id":67689,"date":"2026-01-29T02:41:02","date_gmt":"2026-01-28T18:41:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/67689.html"},"modified":"2026-01-29T02:41:02","modified_gmt":"2026-01-28T18:41:02","slug":"java%e5%86%85%e5%ad%98%e6%ba%a2%e5%87%ba%e6%8e%92%e6%9f%a5%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/67689.html","title":{"rendered":"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357"},"content":{"rendered":"<p>\u597d\u7684&#xff0c;\u8fd9\u662f\u4e00\u4efd\u6392\u67e5 Java \u5185\u5b58\u6ea2\u51fa&#xff08;OutOfMemoryError, OOM&#xff09;\u7684\u5b9e\u6218\u6307\u5357&#xff1a;<\/p>\n<hr \/>\n<h4>Java \u5185\u5b58\u6ea2\u51fa&#xff08;OOM&#xff09;\u6392\u67e5\u5b9e\u6218\u6307\u5357<\/h4>\n<p>Java \u5185\u5b58\u6ea2\u51fa\u662f\u5f00\u53d1\u4e2d\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u95ee\u9898\u3002\u5f53 JVM \u65e0\u6cd5\u5206\u914d\u66f4\u591a\u5185\u5b58\u4ee5\u6ee1\u8db3\u5bf9\u8c61\u521b\u5efa\u6216\u5143\u6570\u636e\u9700\u6c42\u65f6&#xff0c;\u5c31\u4f1a\u629b\u51fa OutOfMemoryError\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u4f60\u7cfb\u7edf\u5730\u6392\u67e5\u548c\u89e3\u51b3 OOM \u95ee\u9898\u3002<\/p>\n<hr \/>\n<h5>\u7b2c\u4e00\u6b65&#xff1a;\u8bc6\u522b OOM \u7c7b\u578b<\/h5>\n<p>OOM \u6709\u591a\u79cd\u7c7b\u578b&#xff0c;\u6bcf\u79cd\u5bf9\u5e94\u4e0d\u540c\u7684\u5185\u5b58\u533a\u57df\u3002\u9996\u5148\u9700\u786e\u5b9a\u9519\u8bef\u7c7b\u578b&#xff1a;<\/p>\n<li>\n<p>java.lang.OutOfMemoryError: Java heap space<\/p>\n<ul>\n<li>\u6700\u5e38\u89c1\u7c7b\u578b&#xff0c;\u8868\u793a \u5806\u5185\u5b58 \u4e0d\u8db3\u3002<\/li>\n<li>\u901a\u5e38\u662f\u521b\u5efa\u4e86\u8fc7\u591a\u5bf9\u8c61\u6216\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f&#xff08;\u5bf9\u8c61\u65e0\u6cd5\u88ab GC \u56de\u6536&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: Metaspace (\u6216 PermGen space&#xff0c;\u5728\u8f83\u8001\u7248\u672c\u4e2d)<\/p>\n<ul>\n<li>\u8868\u793a \u5143\u7a7a\u95f4 (\u5b58\u50a8\u7c7b\u5143\u6570\u636e\u3001\u65b9\u6cd5\u4fe1\u606f\u7b49) \u4e0d\u8db3\u3002<\/li>\n<li>\u901a\u5e38\u7531\u52a0\u8f7d\u8fc7\u591a\u7c7b\u3001\u52a8\u6001\u751f\u6210\u7c7b&#xff08;\u5982\u53cd\u5c04\u3001CGLib\u3001ASM&#xff09;\u6216\u5143\u7a7a\u95f4\u914d\u7f6e\u8fc7\u5c0f\u5f15\u8d77\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: Unable to create new native thread<\/p>\n<ul>\n<li>\u8868\u793a \u7ebf\u7a0b\u6808 \u8d44\u6e90\u4e0d\u8db3\u3002<\/li>\n<li>\u901a\u5e38\u662f\u521b\u5efa\u4e86\u8fc7\u591a\u7ebf\u7a0b&#xff0c;\u8d85\u51fa\u4e86\u7cfb\u7edf\u6216 JVM \u9650\u5236\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: Direct buffer memory<\/p>\n<ul>\n<li>\u8868\u793a \u76f4\u63a5\u5185\u5b58 (\u5806\u5916\u5185\u5b58&#xff0c;\u7531 ByteBuffer.allocateDirect() \u5206\u914d) \u4e0d\u8db3\u3002<\/li>\n<li>\u901a\u5e38\u4e0e NIO \u64cd\u4f5c\u76f8\u5173\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: Requested array size exceeds VM limit<\/p>\n<ul>\n<li>\u5c1d\u8bd5\u5206\u914d\u4e00\u4e2a\u5927\u4e8e JVM \u5141\u8bb8\u6700\u5927\u6570\u7ec4\u5927\u5c0f\u7684\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: GC overhead limit exceeded<\/p>\n<ul>\n<li>GC \u82b1\u8d39\u4e86\u8fc7\u591a\u65f6\u95f4&#xff08;\u8d85\u8fc7 98%&#xff09;\u4f46\u56de\u6536\u6548\u679c\u6781\u5dee&#xff08;\u6bcf\u6b21\u56de\u6536\u91ca\u653e\u7684\u5185\u5b58\u5c11\u4e8e 2%&#xff09;&#xff0c;JVM \u5224\u5b9a\u7ee7\u7eed\u8fd0\u884c\u65e0\u610f\u4e49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>java.lang.OutOfMemoryError: Compressed class space<\/p>\n<ul>\n<li>\u4e0e\u538b\u7f29\u7c7b\u6307\u9488\u76f8\u5173\u7684\u7279\u5b9a\u533a\u57df\u5185\u5b58\u4e0d\u8db3\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u6392\u67e5\u5173\u952e&#xff1a; \u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u6216\u5f02\u5e38\u5806\u6808\u4fe1\u606f&#xff0c;\u660e\u786e\u662f\u54ea\u4e00\u79cd OOM\u3002<\/p>\n<hr \/>\n<h5>\u7b2c\u4e8c\u6b65&#xff1a;\u6536\u96c6\u5173\u952e\u4fe1\u606f<\/h5>\n<li>\n<p>\u83b7\u53d6\u5b8c\u6574\u9519\u8bef\u65e5\u5fd7&#xff1a;<\/p>\n<ul>\n<li>\u5305\u62ec OOM \u7c7b\u578b\u3001\u53d1\u751f\u65f6\u95f4\u3001\u5806\u6808\u8ddf\u8e2a&#xff08;stack trace&#xff09;\u3002\u5806\u6808\u4fe1\u606f\u80fd\u6307\u793a OOM \u53d1\u751f\u65f6\u7a0b\u5e8f\u6b63\u5728\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u83b7\u53d6 JVM \u914d\u7f6e\u53c2\u6570&#xff1a;<\/p>\n<ul>\n<li>\u7279\u522b\u662f\u5185\u5b58\u76f8\u5173\u7684\u53c2\u6570&#xff1a;\n<ul>\n<li>-Xms (\u521d\u59cb\u5806\u5927\u5c0f)<\/li>\n<li>-Xmx (\u6700\u5927\u5806\u5927\u5c0f)<\/li>\n<li>-XX:MetaspaceSize \/ -XX:MaxMetaspaceSize<\/li>\n<li>-XX:MaxDirectMemorySize<\/li>\n<li>-Xss (\u6bcf\u4e2a\u7ebf\u7a0b\u6808\u5927\u5c0f)<\/li>\n<li>\u4f7f\u7528\u7684 GC \u7b97\u6cd5&#xff08;\u5982 -XX:&#043;UseG1GC&#xff09;<\/li>\n<li>\u5176\u4ed6\u76f8\u5173\u53c2\u6570&#xff08;\u5982 -XX:&#043;HeapDumpOnOutOfMemoryError&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7cfb\u7edf\u8d44\u6e90\u4fe1\u606f&#xff1a;<\/p>\n<ul>\n<li>\u7269\u7406\u5185\u5b58\u603b\u91cf\u3001\u53ef\u7528\u5185\u5b58\u3002<\/li>\n<li>CPU \u4f7f\u7528\u7387\u3002<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u9650\u5236&#xff08;\u5982\u7528\u6237\u8fdb\u7a0b\u6570\u3001\u865a\u62df\u5185\u5b58\u5927\u5c0f&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h5>\u7b2c\u4e09\u6b65&#xff1a;\u5206\u6790\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/h5>\n<li>\n<p>\u542f\u7528\u5806\u8f6c\u50a8 (Heap Dump)&#xff1a;<\/p>\n<ul>\n<li>\u5728\u542f\u52a8 JVM \u65f6\u6dfb\u52a0\u53c2\u6570 -XX:&#043;HeapDumpOnOutOfMemoryError\u3002\u8fd9\u6837\u5728\u53d1\u751f OOM \u65f6&#xff0c;JVM \u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u5806\u8f6c\u50a8\u6587\u4ef6&#xff08;\u901a\u5e38\u662f .hprof \u6587\u4ef6&#xff09;\u3002<\/li>\n<li>\u5982\u679c\u95ee\u9898\u53ef\u91cd\u73b0&#xff0c;\u4e5f\u53ef\u4ee5\u5728\u95ee\u9898\u53d1\u751f\u524d\u624b\u52a8\u89e6\u53d1\u8f6c\u50a8&#xff1a;\n<ul>\n<li>\u4f7f\u7528 jmap \u5de5\u5177&#xff1a;jmap -dump:format&#061;b,file&#061;heapdump.hprof &lt;pid&gt; (\u66ff\u6362 &lt;pid&gt; \u4e3a Java \u8fdb\u7a0b ID)\u3002<\/li>\n<li>\u4f7f\u7528 jcmd \u5de5\u5177&#xff1a;jcmd &lt;pid&gt; GC.heap_dump \/path\/to\/heapdump.hprof\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5206\u6790\u5806\u8f6c\u50a8\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528\u5185\u5b58\u5206\u6790\u5de5\u5177&#xff08;Memory Analyzer Tool, MAT&#xff09;\u662f \u6700\u6709\u6548 \u7684\u65b9\u6cd5\u3002\n<ul>\n<li>\u5b89\u88c5 MAT&#xff1a; \u4e0b\u8f7d Eclipse MAT (Memory Analyzer Tool)\u3002<\/li>\n<li>\u6253\u5f00 .hprof \u6587\u4ef6&#xff1a; \u4f7f\u7528 MAT \u52a0\u8f7d\u5806\u8f6c\u50a8\u6587\u4ef6\u3002<\/li>\n<li>\u8bc6\u522b\u95ee\u9898&#xff1a;\n<ul>\n<li>Leak Suspects Report (\u6cc4\u6f0f\u5acc\u7591\u62a5\u544a)&#xff1a; MAT \u4f1a\u81ea\u52a8\u751f\u6210\u62a5\u544a&#xff0c;\u5217\u51fa\u53ef\u80fd\u5bfc\u81f4\u6cc4\u6f0f\u7684\u5bf9\u8c61\u548c\u5f15\u7528\u94fe\u3002\u8fd9\u662f \u9996\u8981\u67e5\u770b \u7684\u5730\u65b9\u3002<\/li>\n<li>Histogram (\u76f4\u65b9\u56fe)&#xff1a; \u67e5\u770b\u6309\u7c7b\u6216\u7c7b\u52a0\u8f7d\u5668\u7edf\u8ba1\u7684\u5bf9\u8c61\u6570\u91cf\u548c\u5360\u7528\u5185\u5b58\u5927\u5c0f\u3002\u91cd\u70b9\u5173\u6ce8\u6570\u91cf\u5f02\u5e38\u591a\u6216\u5360\u7528\u5185\u5b58\u5927\u7684\u7c7b\u3002<\/li>\n<li>Dominator Tree (\u652f\u914d\u6811)&#xff1a; \u67e5\u770b\u54ea\u4e9b\u5bf9\u8c61\u6301\u6709\u4e86\u5927\u91cf\u5185\u5b58&#xff0c;\u4ee5\u53ca\u5b83\u4eec\u7684\u5f15\u7528\u8def\u5f84\u3002\u8fd9\u6709\u52a9\u4e8e\u627e\u5230\u5185\u5b58\u6d88\u8017\u7684\u201c\u6839\u201d\u3002<\/li>\n<li>\u5bf9\u6bd4\u5feb\u7167&#xff1a; \u5982\u679c\u80fd\u5728 OOM \u524d\u83b7\u53d6\u4e00\u4e2a\u5806\u5feb\u7167&#xff0c;\u5728 MAT \u4e2d\u5bf9\u6bd4\u4e24\u4e2a\u5feb\u7167&#xff0c;\u53ef\u4ee5\u6e05\u6670\u5730\u770b\u51fa\u54ea\u4e9b\u5bf9\u8c61\u5728\u589e\u957f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u5176\u4ed6\u53ef\u9009\u5de5\u5177&#xff1a;jvisualvm (JDK \u81ea\u5e26), YourKit, JProfiler \u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u76d1\u63a7 GC \u6d3b\u52a8&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528 jstat \u5de5\u5177\u76d1\u63a7 GC \u7edf\u8ba1\u4fe1\u606f&#xff1a;\n<ul>\n<li>jstat -gcutil &lt;pid&gt; 1000 (\u6bcf 1000 \u6beb\u79d2\u6253\u5370\u4e00\u6b21 GC \u7edf\u8ba1\u4fe1\u606f)<\/li>\n<li>\u5173\u6ce8 S0C\/S1C\/S0U\/S1U (Survivor \u533a\u5bb9\u91cf\/\u4f7f\u7528\u91cf)&#xff0c;EC\/EU (Eden \u533a\u5bb9\u91cf\/\u4f7f\u7528\u91cf)&#xff0c;OC\/OU (\u8001\u5e74\u4ee3\u5bb9\u91cf\/\u4f7f\u7528\u91cf)&#xff0c;MC\/MU (\u5143\u7a7a\u95f4\u5bb9\u91cf\/\u4f7f\u7528\u91cf)&#xff0c;YGC\/YGCT (Young GC \u6b21\u6570\/\u65f6\u95f4)&#xff0c;FGC\/FGCT (Full GC \u6b21\u6570\/\u65f6\u95f4)\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4f7f\u7528 jcmd &lt;pid&gt; GC.heap_info \u67e5\u770b\u5806\u5185\u5b58\u5206\u5e03\u3002<\/li>\n<li>\u542f\u7528 GC \u65e5\u5fd7&#xff1a;\n<ul>\n<li>\u6dfb\u52a0 JVM \u53c2\u6570 -XX:&#043;PrintGCDetails -XX:&#043;PrintGCDateStamps -Xloggc:\/path\/to\/gc.log\u3002<\/li>\n<li>\u5206\u6790 GC \u65e5\u5fd7&#xff0c;\u67e5\u770b GC \u9891\u7387\u3001\u8017\u65f6\u3001\u56de\u6536\u6548\u679c&#xff08;\u5982\u8001\u5e74\u4ee3\u662f\u5426\u6301\u7eed\u589e\u957f&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5206\u6790\u7ebf\u7a0b\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\u5bf9\u4e8e Unable to create new native thread&#xff0c;\u68c0\u67e5\u7ebf\u7a0b\u6570\u91cf&#xff1a;\n<ul>\n<li>\u4f7f\u7528 jstack &lt;pid&gt; \u83b7\u53d6\u7ebf\u7a0b\u5806\u6808\u4fe1\u606f&#xff0c;\u7edf\u8ba1\u7ebf\u7a0b\u6570\u91cf\u3002<\/li>\n<li>\u4f7f\u7528 top -H -p &lt;pid&gt; (Linux) \u6216 Process Explorer (Windows) \u67e5\u770b\u8fdb\u7a0b\u7684\u7ebf\u7a0b\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5206\u6790 jstack \u8f93\u51fa&#xff0c;\u67e5\u770b\u662f\u5426\u6709\u5927\u91cf\u7ebf\u7a0b\u963b\u585e\u5728\u76f8\u540c\u4f4d\u7f6e\u6216\u6267\u884c\u76f8\u540c\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5206\u6790\u76f4\u63a5\u5185\u5b58\u4f7f\u7528&#xff1a;<\/p>\n<ul>\n<li>\u5bf9\u4e8e Direct buffer memory&#xff0c;\u6392\u67e5\u4f7f\u7528 ByteBuffer.allocateDirect() \u6216 NIO \u76f8\u5173\u64cd\u4f5c\u7684\u4ee3\u7801\u3002<\/li>\n<li>\u4f7f\u7528 jcmd &lt;pid&gt; VM.native_memory \u67e5\u770b Native Memory Tracking (NMT) \u4fe1\u606f&#xff08;\u9700\u5728\u542f\u52a8\u65f6\u5f00\u542f -XX:NativeMemoryTracking&#061;summary \u6216 detail&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h5>\u7b2c\u56db\u6b65&#xff1a;\u5b9a\u4f4d\u95ee\u9898\u6839\u6e90\u4e0e\u4fee\u590d<\/h5>\n<p>\u6839\u636e\u5206\u6790\u7ed3\u679c&#xff0c;\u9488\u5bf9\u6027\u89e3\u51b3&#xff1a;<\/p>\n<ul>\n<li>\n<p>Java heap space \/ GC overhead limit exceeded&#xff1a;<\/p>\n<ul>\n<li>\u5185\u5b58\u6cc4\u6f0f&#xff1a; \u6839\u636e MAT \u5206\u6790\u7ed3\u679c&#xff0c;\u627e\u5230\u5e76\u4fee\u590d\u6cc4\u6f0f\u70b9\u3002\u5e38\u89c1\u539f\u56e0&#xff1a;\n<ul>\n<li>\u9759\u6001\u96c6\u5408\u7c7b&#xff08;\u5982 static HashMap&#xff09;\u65e0\u8282\u5236\u5730\u589e\u957f\u3002<\/li>\n<li>\u672a\u5173\u95ed\u8d44\u6e90&#xff08;\u6570\u636e\u5e93\u8fde\u63a5\u3001\u6587\u4ef6\u6d41\u3001\u7f51\u7edc\u8fde\u63a5\u7b49&#xff09;&#xff0c;\u5bfc\u81f4\u5173\u8054\u5bf9\u8c61\u65e0\u6cd5\u91ca\u653e\u3002<\/li>\n<li>\u76d1\u542c\u5668\/\u56de\u8c03\u672a\u6b63\u786e\u6ce8\u9500\u3002<\/li>\n<li>\u7f13\u5b58\u4f7f\u7528\u4e0d\u5f53&#xff0c;\u7f3a\u4e4f\u6dd8\u6c70\u7b56\u7565\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5408\u7406\u8bbe\u8ba1&#xff1a; \u907f\u514d\u521b\u5efa\u751f\u547d\u5468\u671f\u8fc7\u957f\u7684\u5927\u5bf9\u8c61&#xff08;\u5982\u8d85\u5927\u6570\u7ec4\u3001\u96c6\u5408&#xff09;\u3002\u8003\u8651\u5bf9\u8c61\u6c60\u5316\u3002<\/li>\n<li>\u4f18\u5316 GC&#xff1a; \u8c03\u6574\u5806\u5927\u5c0f (-Xmx)&#xff0c;\u9009\u62e9\u5408\u9002\u7684 GC \u7b97\u6cd5\u548c\u53c2\u6570&#xff08;\u5982 G1 \u7684 -XX:MaxGCPauseMillis&#xff09;\u3002<\/li>\n<li>\u8c03\u5927\u5806&#xff1a; \u5982\u679c\u786e\u5b9e\u662f\u5e94\u7528\u9700\u8981\u5927\u91cf\u5185\u5b58\u4e14\u65e0\u6cc4\u6f0f&#xff0c;\u53ef\u9002\u5f53\u589e\u52a0 -Xmx&#xff08;\u9700\u786e\u4fdd\u7269\u7406\u5185\u5b58\u8db3\u591f&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Metaspace \/ Compressed class space&#xff1a;<\/p>\n<ul>\n<li>\u68c0\u67e5\u662f\u5426\u6709\u6846\u67b6&#xff08;\u5982 Spring AOP, Hibernate&#xff09;\u52a8\u6001\u751f\u6210\u5927\u91cf\u7c7b\u3002<\/li>\n<li>\u6392\u67e5\u81ea\u5b9a\u4e49\u7c7b\u52a0\u8f7d\u5668\u662f\u5426\u9891\u7e41\u52a0\u8f7d\/\u5378\u8f7d\u7c7b\u3002<\/li>\n<li>\u589e\u52a0\u5143\u7a7a\u95f4\u5927\u5c0f&#xff1a;-XX:MaxMetaspaceSize\u3002<\/li>\n<li>\u51cf\u5c11\u52a8\u6001\u7c7b\u751f\u6210&#xff08;\u5982\u679c\u53ef\u80fd&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Unable to create new native thread&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u5316\u4ee3\u7801&#xff0c;\u51cf\u5c11\u7ebf\u7a0b\u521b\u5efa&#xff08;\u4f7f\u7528\u7ebf\u7a0b\u6c60&#xff09;\u3002<\/li>\n<li>\u8c03\u6574 -Xss \u51cf\u5c0f\u5355\u4e2a\u7ebf\u7a0b\u6808\u5927\u5c0f&#xff08;\u8c28\u614e\u64cd\u4f5c&#xff0c;\u53ef\u80fd\u5bfc\u81f4 StackOverflowError&#xff09;\u3002<\/li>\n<li>\u68c0\u67e5\u64cd\u4f5c\u7cfb\u7edf\u5bf9\u7528\u6237\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u6570\u7684\u9650\u5236 (ulimit -u)&#xff0c;\u5fc5\u8981\u65f6\u8c03\u6574\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Direct buffer memory&#xff1a;<\/p>\n<ul>\n<li>\u68c0\u67e5\u4f7f\u7528\u76f4\u63a5\u5185\u5b58\u7684\u4ee3\u7801&#xff08;\u5982 Netty, NIO&#xff09;&#xff0c;\u786e\u4fdd ByteBuffer \u5728\u4f7f\u7528\u540e\u88ab\u6e05\u7406&#xff08;\u6216\u663e\u5f0f\u8c03\u7528 ((DirectBuffer) buffer).cleaner().clean()&#xff0c;\u4f46\u9700\u8c28\u614e&#xff09;\u3002<\/li>\n<li>\u589e\u52a0\u76f4\u63a5\u5185\u5b58\u9650\u5236&#xff1a;-XX:MaxDirectMemorySize\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Requested array size exceeds VM limit&#xff1a;<\/p>\n<ul>\n<li>\u68c0\u67e5\u5c1d\u8bd5\u5206\u914d\u8d85\u5927\u6570\u7ec4\u7684\u4ee3\u7801\u903b\u8f91&#xff0c;\u907f\u514d\u5206\u914d\u8d85\u8fc7 Integer.MAX_VALUE &#8211; 8 \u5927\u5c0f\u7684\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>\u7b2c\u4e94\u6b65&#xff1a;\u9a8c\u8bc1\u4e0e\u9884\u9632<\/h5>\n<ul>\n<li>\u9a8c\u8bc1\u4fee\u590d&#xff1a; \u5728\u6d4b\u8bd5\u73af\u5883\u6216\u7070\u5ea6\u73af\u5883\u4e2d\u9a8c\u8bc1\u4fee\u590d\u63aa\u65bd\u662f\u5426\u6709\u6548\u3002<\/li>\n<li>\u6301\u7eed\u76d1\u63a7&#xff1a; \u5728\u751f\u4ea7\u73af\u5883\u914d\u7f6e\u76d1\u63a7&#xff08;\u5982 Prometheus &#043; Grafana&#xff09;&#xff0c;\u8ddf\u8e2a\u5173\u952e\u6307\u6807&#xff1a;\n<ul>\n<li>JVM \u5185\u5b58\u5404\u533a\u57df\u4f7f\u7528\u91cf&#xff08;Heap, Metaspace, Direct Buffer&#xff09;\u3002<\/li>\n<li>GC \u9891\u7387\u548c\u8017\u65f6\u3002<\/li>\n<li>\u7ebf\u7a0b\u6570\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u538b\u529b\u6d4b\u8bd5&#xff1a; \u5b9a\u671f\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5\u548c\u957f\u65f6\u95f4\u7a33\u5b9a\u6027\u6d4b\u8bd5&#xff0c;\u63d0\u524d\u66b4\u9732\u6f5c\u5728\u95ee\u9898\u3002<\/li>\n<li>\u4ee3\u7801\u5ba1\u67e5&#xff1a; \u5173\u6ce8\u8d44\u6e90\u7ba1\u7406&#xff08;try-with-resources&#xff09;\u3001\u7f13\u5b58\u4f7f\u7528\u3001\u96c6\u5408\u7c7b\u7ba1\u7406\u7b49\u3002<\/li>\n<\/ul>\n<hr \/>\n<p>\u603b\u7ed3&#xff1a; OOM \u6392\u67e5\u662f\u4e00\u4e2a\u7cfb\u7edf\u5de5\u7a0b&#xff0c;\u9700\u8981\u7ed3\u5408\u65e5\u5fd7\u5206\u6790\u3001\u5de5\u5177\u4f7f\u7528&#xff08;jmap, jstack, jstat, MAT&#xff09;\u548c\u4ee3\u7801\u5ba1\u67e5\u3002\u5173\u952e\u5728\u4e8e\u5feb\u901f\u51c6\u786e\u5b9a\u4f4d OOM \u7c7b\u578b\u548c\u5185\u5b58\u6d88\u8017\u70ed\u70b9&#xff0c;\u518d\u9488\u5bf9\u6027\u4f18\u5316\u4ee3\u7801\u6216\u8c03\u6574 JVM \u914d\u7f6e\u3002\u6301\u7eed\u76d1\u63a7\u548c\u9884\u9632\u6027\u63aa\u65bd\u540c\u6837\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u7684&#xff0c;\u8fd9\u662f\u4e00\u4efd\u6392\u67e5 Java \u5185\u5b58\u6ea2\u51fa&#xff08;OutOfMemoryError, OOM&#xff09;\u7684\u5b9e\u6218\u6307\u5357&#xff1a; Java \u5185\u5b58\u6ea2\u51fa&#xff08;OOM&#xff09;\u6392\u67e5\u5b9e\u6218\u6307\u5357<br \/>\nJava \u5185\u5b58\u6ea2\u51fa\u662f\u5f00\u53d1\u4e2d\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u95ee\u9898\u3002\u5f53 JVM \u65e0\u6cd5\u5206\u914d\u66f4\u591a\u5185\u5b58\u4ee5\u6ee1\u8db3\u5bf9\u8c61\u521b\u5efa\u6216\u5143\u6570\u636e\u9700\u6c42\u65f6&#xff0c;\u5c31\u4f1a\u629b\u51fa OutOfMemoryError\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u4f60\u7cfb\u7edf\u5730\u6392\u67e5\u548c\u89e3\u51b3 OOM \u95ee\u9898\u3002 \u7b2c\u4e00\u6b65&#xff1a;\u8bc6\u522b OOM \u7c7b\u578b<br \/>\nO<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190],"topic":[],"class_list":["post-67689","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/67689.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u597d\u7684&#xff0c;\u8fd9\u662f\u4e00\u4efd\u6392\u67e5 Java \u5185\u5b58\u6ea2\u51fa&#xff08;OutOfMemoryError, OOM&#xff09;\u7684\u5b9e\u6218\u6307\u5357&#xff1a; Java \u5185\u5b58\u6ea2\u51fa&#xff08;OOM&#xff09;\u6392\u67e5\u5b9e\u6218\u6307\u5357 Java \u5185\u5b58\u6ea2\u51fa\u662f\u5f00\u53d1\u4e2d\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u95ee\u9898\u3002\u5f53 JVM \u65e0\u6cd5\u5206\u914d\u66f4\u591a\u5185\u5b58\u4ee5\u6ee1\u8db3\u5bf9\u8c61\u521b\u5efa\u6216\u5143\u6570\u636e\u9700\u6c42\u65f6&#xff0c;\u5c31\u4f1a\u629b\u51fa OutOfMemoryError\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u4f60\u7cfb\u7edf\u5730\u6392\u67e5\u548c\u89e3\u51b3 OOM \u95ee\u9898\u3002 \u7b2c\u4e00\u6b65&#xff1a;\u8bc6\u522b OOM \u7c7b\u578b O\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/67689.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-28T18:41:02+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/67689.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/67689.html\",\"name\":\"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-28T18:41:02+00:00\",\"dateModified\":\"2026-01-28T18:41:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/67689.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/67689.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/67689.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/67689.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u597d\u7684&#xff0c;\u8fd9\u662f\u4e00\u4efd\u6392\u67e5 Java \u5185\u5b58\u6ea2\u51fa&#xff08;OutOfMemoryError, OOM&#xff09;\u7684\u5b9e\u6218\u6307\u5357&#xff1a; Java \u5185\u5b58\u6ea2\u51fa&#xff08;OOM&#xff09;\u6392\u67e5\u5b9e\u6218\u6307\u5357 Java \u5185\u5b58\u6ea2\u51fa\u662f\u5f00\u53d1\u4e2d\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u95ee\u9898\u3002\u5f53 JVM \u65e0\u6cd5\u5206\u914d\u66f4\u591a\u5185\u5b58\u4ee5\u6ee1\u8db3\u5bf9\u8c61\u521b\u5efa\u6216\u5143\u6570\u636e\u9700\u6c42\u65f6&#xff0c;\u5c31\u4f1a\u629b\u51fa OutOfMemoryError\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u4f60\u7cfb\u7edf\u5730\u6392\u67e5\u548c\u89e3\u51b3 OOM \u95ee\u9898\u3002 \u7b2c\u4e00\u6b65&#xff1a;\u8bc6\u522b OOM \u7c7b\u578b O","og_url":"https:\/\/www.wsisp.com\/helps\/67689.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-28T18:41:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/67689.html","url":"https:\/\/www.wsisp.com\/helps\/67689.html","name":"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-28T18:41:02+00:00","dateModified":"2026-01-28T18:41:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/67689.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/67689.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/67689.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u5185\u5b58\u6ea2\u51fa\u6392\u67e5\u5b9e\u6218\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/67689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=67689"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/67689\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=67689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=67689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=67689"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=67689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}