How to request JVM garbage collection (not from code) when run from Windows command-line

前端 未结 4 1819
执笔经年
执笔经年 2020-12-31 05:41

how could I request Java garbage collection externally, starting the program from JAR (Windows BAT used)?

  • From the Java code I can do it with System.gc(
4条回答
  •  鱼传尺愫
    2020-12-31 06:34

    For a purely command-line approach, you should be able to use jcmd. I believe jcmd has been part of the standard JDK install since at least Java 1.7. The command would be something like this:

    jcmd  GC.run
    

    You can get a list of available diagnostic commands that jcmd provides for a particular process like this:

    jcmd  help
    

提交回复
热议问题