So I am looking at a heap with jmap on a remote box and I want to force garbage collection on it. How do you do this without popping into jvisualvm or jconsole and friends?<
just:
kill -SIGQUIT <PID>
Addition to user3198490's answer. Running this command might give you the following error message:
$ jcmd 1805 GC.run
[16:08:01]
1805:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
...
This can be solved with help of this stackoverflow answer
sudo -u <process_owner> jcmd <pid> GC.run
where <process_owner>
is the user that runs the process with PID <pid>
. You can get both from top
or htop
If you are using jolokia with your application, you can trigger a garbage collection with this command:
curl http://localhost:8558/jolokia/exec/java.lang:type=Memory/gc