JConsole Total loaded classes behaviour

2.2k views Asked by At

I monitored a Java7 application for a couple of week and I observed a couple of things that i would like to understand.

From the application start the number of total loaded classes has grown constantly, I think that this is normal since the application (based on netty 3.6 library) open and closed a lot of tcp connections hourly. I don't think I should worry about this also because the Current classes loaded counter did not grown.

What I can't understand it's why approximately every 7 days the number of the total loaded class drops to the current classes loaded counter. Also the Heap Memory usage seems follow the same pattern: the heap space grows till 70mb and then decreases to 20mb.

It is like every 7 days a more "deeper" execution of the Garbage collector it is executed.

The application has never been restarted.

Can someone explain me this behaviour? Thanks.

P.S. Unfortunately i couldn't take a screenshot of the JConsole.

1

There are 1 answers

0
Pace On BEST ANSWER

In the Oracle JVM there are multiple pools of memory in the heap. One of them is the old gen pool, another is the perm gen pool. The old gen pool contains objects that have survived a few garbage collections. The perm gen pool contains loaded classes and other "permanent" data.

Heap pools are garbage collected differently. The standard garbage collection that you see run often runs on the eden pool which is where newly created objects are placed. The theory is that if you have a lot of short lived objects then those can be garbage collected often in a small heap. In the meantime your longer lived objects get promoted to the older pools and collected less often.

This is all to allow more efficient garbage collection as longer lived objects aren't considered for collection as often as short lived objects. So the "deeper" execution you're seeing is probably when the old gen pool is getting collected. It just so happens that Oracle decided to implement things so that the perm gen pool gets garbage collected at the same time as the old gen pool which is why both of them drop at the same time.

Finally, simply opening and closing TCP connections should not cause new classes to get loaded. What is likely happening is that some library is creating new dynamic proxies when a connection arrives. This dynamic proxy is a brand new class created at runtime and when it is created it will increase your total classes loaded count.

References:

In Java is Permanent Generation space garbage collected?

Java 6 garbage collection details (from Oracle)