How do you Force Garbage Collection from the Shell?

前端 未结 9 679
滥情空心
滥情空心 2020-11-30 17:42

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?<

9条回答
  •  自闭症患者
    2020-11-30 18:11

    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  jcmd  GC.run
    

    where is the user that runs the process with PID . You can get both from top or htop

提交回复
热议问题