java - Tomcat,内存泄漏 char[] 和 ThreadWithAttributes

标签 java tomcat memory-leaks tomcat6

我的 tomcat (Apache Tomcat/6.0.18) 似乎有内存泄漏。

初步分析

有一段时间在几台服务器上堆利用率超过了 90%。然后我进行了堆转储及其分析,指出了两个可能的泄漏:

4 550 instances of "char[]", loaded by "" occupy 321 358 144 (42,39%) bytes.

Biggest instances:

char[5102000] @ 0xd18668c8 \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00... - 10 204 016 (1,35%) bytes.


392 instances of "org.apache.tomcat.util.threads.ThreadWithAttributes", loaded by "org.apache.catalina.loader.StandardClassLoader @ 0xbb003c30" occupy 151 940 704 (20,04%) bytes.

其中char[5102000]重复多次,填null。

分析

org.apache.tomcat.util.threads.ThreadWithAttributes

支配树分析表明罪魁祸首是 CA Wily Introscope。

╔═══════════════════════════════════════════════════════════════════════════════════════╦════════════════════════╦═════════════════╦═════════════════╦═════════════╗
║   Class Name                                                                          ║        Objects         ║  Shallow Heap   ║  Retained Heap  ║  Percentage ║
╠═══════════════════════════════════════════════════════════════════════════════════════╬════════════════════════╬═════════════════╬═════════════════╬═════════════╣
║ org.apache.tomcat.util.threads.ThreadWithAttributes                                   ║ 392                    ║        53 312   ║    151 940 704  ║ 20,04%      ║
║ #-java.lang.ThreadLocal$ThreadLocalMap$Entry                                          ║  254 047               ║     8 129 504   ║    146 384 296  ║ 19,31%      ║
║ ##- com.wily.util.adt.CanonicalObjectPoolWithKey                                      ║ 391                    ║        12 512   ║     72 506 184  ║ 9,56%       ║
║ ##- java.util.HashMap                                                                 ║  199 734               ║     7 989 360   ║     40 377 784  ║ 5,33%       ║
║ ###- com.wily.util.adt.WeakWeakIdentityHashMap                                        ║ 391                    ║         9 384   ║     11 503 344  ║ 1,52%       ║
║ #java.util.HashMap$Entry                                                              ║  207 683 #  4 984 392  ║     16 396 456  ║ 2,16%           ║             ║
║ ####- com.wily.introscope.agent.trace.BlamePointTracer$DataAccumulatorGroup           ║   49 807               ║     1 593 824   ║      1 593 824  ║ 0,21%       ║
║ ####- com.wily.introscope.agent.trace.servlet.ServletObjectFactory$MethodKey          ║    2 563               ║        61 512   ║         62 840  ║ 0,01%       ║
║ #####- com.wily.introscope.stat.gatherer.IntegerAverageGatherer                       ║ 92                     ║         5 152   ║         10 304  ║ 0,00%       ║
║ #####- com.wily.introscope.stat.gatherer.IntervalCounterGatherer                      ║ 109                    ║         4 360   ║          4 360  ║ 0,00%       ║
║ #####- com.wily.introscope.stat.gatherer.IntegerFluctuatingCounterGatherer            ║ 55                     ║         3 080   ║          3 080  ║ 0,00%       ║
║ #####- com.wily.introscope.stat.gatherer.IntegerAggregatingFluctuatingCounterGatherer ║ 54                     ║         3 024   ║          3 024  ║ 0,00%       ║
╚═══════════════════════════════════════════════════════════════════════════════════════╩════════════════════════╩═════════════════╩═════════════════╩═════════════╝

字符[]

支配树分析没有显示 - 唯一的积累点是 char[]。分析“Merge Shortest Paths to GC Roots”直接指向org.apache.tomcat.util.threads.ThreadWithAttributes。

╔══════════════════════════════════════════════════════════════════════════════════════════╦════════════════╦════════════════╦═════════════════════╦════════════════╗
║                                        Class Name                                        ║  Ref. Objects  ║  Shallow Heap  ║  Ref. Shallow Heap  ║  Retained Heap ║
╠══════════════════════════════════════════════════════════════════════════════════════════╬════════════════╬════════════════╬═════════════════════╬════════════════╣
║ org.apache.tomcat.util.threads.ThreadWithAttributes @ 0xd0b12cb8  TP-Processor203 Thread ║              1 ║ 136            ║         10 204 016  ║        240 216 ║
║ - <Java Local> char[5102000] @ 0xd18668c8  \u0000\u0000...                               ║              1 ║    10 204 016  ║         10 204 016  ║     10 204 016 ║
╚══════════════════════════════════════════════════════════════════════════════════════════╩════════════════╩════════════════╩═════════════════════╩════════════════╝

问题

是什么负责创建许多用 null 填充的对象 char[]? hea不占空间怎么补救?

最佳答案

尝试禁用 JspWriterImpl 池,在 JRE 启动命令中添加此参数:

-Dorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true

这将在使用后释放 JspWriterImpl 缓冲区

关于java - Tomcat,内存泄漏 char[] 和 ThreadWithAttributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19448005/

相关文章:

c++ - 追踪 WinSock MFC 应用程序中句柄泄漏的来源

java - 如何使用 yourkit 调查类加载器泄漏

java - 如何在tomcat中部署一个Ldap war文件?访问站点 localhost :8080

tomcat - JMeter - AJP 采样器因非 HTTP 响应消息而失败

java - java代码中如何调用Tomcat的startup.bat

c++ - malloc、struct、std::string 和 free 可能发生内存泄漏

java - Libgdx BitmapFont NullPointerException

java - 未指定尺寸的 Android 裁剪图像

java - 查找数组中 k 个最小数字的索引的算法

java - catalina.out 每日滚动