Search code examples
javagarbage-collectionjvmwindows-server-2008-r2java-6

Why does the Java garbage collector kick in when there is plenty of available RAM?


C# dev here, forced to deal with Java... I am interfacing to a Java Web Service, which is quite memory and CPU heavy. It .

Facts:

  • Runs under Tomcat and it's Java 1.6.x
  • It's all on Windows Server 2008 R2, x64 with 32 GB of RAM.
  • Tomcat is set to have 16GB of RAM
  • The Web Service typically consumes about 6.5 GB.

Every now and then, the web service is hit by Garbage Collection storms and it slows down processing (as determined by the vendor of the Java Web Service).

My question, not knowing much about Java GC, is why does GC even kick in if there is plenty of RAM available. Is there some setting which tells it to kick when there is little memory left?

My frame of reference is the .NET GC, which only kicks in when there is memory pressure.


Solution

  • There are several garbage collection models available in Java. You can experiment to see which one has the least impact in your particular use case. See:

    I was able to get much smoother / predictable performance in a web service a while back by selecting an appropriate collection model.