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

前端 未结 4 1816
执笔经年
执笔经年 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:40

    You normally should not have any reason to force garbage collection. Doing so, messes up the garbage collector algorithms (mainly their performance). It will also slow down the program while garbage is being collected. If there is a memory issue, you should use memory tracing tools to find out where references are being held? (Are listeners unregistered?)

    As in the other answers, you can use jconsole or jvisualvm. You can also use jmx to do it programmatically.

提交回复
热议问题