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/

相关文章:

Java - 将 ASCII 转换为不带前导零的二进制

java - 使用servlet创建文件夹并上传文件

在 IE10 中重新加载另一个框架时,Java Applet 失败/消失

eclipse - 在 eclipse 中的 tomcat 上运行 GWT

hibernate - 在 Grails/Tomcat 上的长批处理期间出现 OutOfMemoryError

java - 最终字段如何不泄漏内存?

c# - ObjectContext 正在泄漏分离实体的内存

java - Blackberry:如何找到已连接网络的子网掩码

java - oauth2 的 Tomcat 领域?

c++ - Visual Studio 2017 在使用 Poco Xml 文档时检测内存泄漏