i use ehCache as a temporary memory stack (serves as a cache). No serializable, just String Object.
All incoming HTTP request data are store in ehcache. And there is a asynch scheduler process that takes the data from ehcache by "getKeys()" and remove the key/value by removeElement(element) after storing them into a proprietary Database.
This system runs fine and smooth but when the system runs for sometime (1 hour), the memory was fully utilized (2.5GB) and all CPU time was taken to perform GC.
The asynch process log the remaining size of the cache everytime it start. The cache.getSize() maintain at around Max:3500, and Min:300 when it finish it work.
I thought there is a Memory Leak on this application. so i used Eclipse MAT to look at the Heap Dump (on a smaller memory utilization to avoid parsing 2.5GB of data). After running the Suspect Report, i got these comments from MAT:
One instance of "org.apache.catalina.session.StandardManager" loaded by "org.apache.catalina.loader.StandardClassLoader @ 0x853f0280" occupies 73,407,072 (76.05%) bytes. The memory is accumulated in one instance of "java.util.concurrent.ConcurrentHashMap$Segment" loaded by "<system class loader>".
and i found out that many empty collections that is not GC from the Top Consumer report:
Detected the following empty collections:
24,692 instances of java.util.Hashtable retain >= 4,345,728 bytes.
393,990 instances of java.util.concurrent.ConcurrentHashMap$Segment retain >= 50,430,720 bytes.
All the variable that related to the ehcache are at class's method level and no static define on them.
Any idea why GC unable to clean the cache?
Version of ehcache = 2.2.0