如何从Windows命令行运行时请求JVM垃圾回收(而不是代码) [英] How to request JVM garbage collection (not from code) when run from Windows command-line

查看:337
本文介绍了如何从Windows命令行运行时请求JVM垃圾回收(而不是代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从外部请求Java垃圾收集,从JAR(Windows BAT使用)启动程序?

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


  • 从Java代码中我可以用 System.gc() / li>
  • 运行JNLP发行版时,我从控制面板/ Java / ...打开了Java控制台,并且此Java控制台提供了手动垃圾回收。

  • From the Java code I can do it with System.gc()
  • When running a JNLP distribution, I get this "Java console" turned on from Control Panel / Java / ... and this Java console provides manual garbage collection.

但是...当我从命令行/ bat运行jar时,java控制台似乎没有打开。

But... When I'm running the jar from command-line / bat the java console doesn't seem to open. Couldn't find help with a brief googling, maybe somebody here?

推荐答案

您可以使用 jconsole 连接到本地运行的JVM - 这提供了一个Perform

You can use jconsole to connect to a JVM that is running locally - This provides a "Perform GC" button on the GUI.

您需要在启动java进程时指定 -Dcom.sun.management.jmxremote

You'll need to specify -Dcom.sun.management.jmxremote when you kick off your java process.

这篇关于如何从Windows命令行运行时请求JVM垃圾回收(而不是代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆