Tracking down a memory leak / garbage-collection issue in Java

后端 未结 7 1180
故里飘歌
故里飘歌 2020-12-02 04:34

This is a problem I have been trying to track down for a couple months now. I have a java app running that processes xml feeds and stores the result in a database. There hav

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 05:12

    I would look for directly allocated ByteBuffer.

    From the javadoc.

    A direct byte buffer may be created by invoking the allocateDirect factory method of this class. The buffers returned by this method typically have somewhat higher allocation and deallocation costs than non-direct buffers. The contents of direct buffers may reside outside of the normal garbage-collected heap, and so their impact upon the memory footprint of an application might not be obvious. It is therefore recommended that direct buffers be allocated primarily for large, long-lived buffers that are subject to the underlying system's native I/O operations. In general it is best to allocate direct buffers only when they yield a measureable gain in program performance.

    Perhaps the Tomcat code uses this do to I/O; configure Tomcat to use a different connector.

    Failing that you could have a thread that periodically executes System.gc(). "-XX:+ExplicitGCInvokesConcurrent" might be an interesting option to try.

提交回复
热议问题