Sometimes Java processes start accumulating memory over time and do not give them back to the OS. In previous versions of Java, this was a limitation of the JVM. In Java 8 and newer, with the arrival of the G1 garbage collector, the JVM releases memory back to the OS after a GC run.
Now since this is possible, calling a GC, although there is still free memory available becomes a different meaning. On the other hand most application aren’t build with that in mind, so they do not offer any public interface to trigger a GC.
Luckily, the Oracle JDK has a tool for that call “jcmd”.
Now, to invoke this regularly and not only invoking one, but all engines running this application jar, I used the following script and hooked that into the crontab.
Now, every couple of hours, a GC is invoked on the JVM, so the memory bloat stays within reason.
- Java SPI - a simple hello world service
- FormDataHandler implements com.sun.net.httpserver.HttpHandler
- ant task to show content of a jar file
- debugging a java application with an interactive shell
- add jar to the classpath at runtime in jjs (the hacky way)
- doing objects in jjs
- read the content of a file in one line in jjs
- print something to the console in jjs
- using jjs under osx
- improve TIBCO Designer tester performance under linux