读取Java JVM启动参数(例如-Xmx) [英] Read Java JVM startup parameters (eg -Xmx)

查看:1378
本文介绍了读取Java JVM启动参数(例如-Xmx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出是否有一种方法来确定JVM启动属性从一个正在运行的java进程。具体来说,我试图找出存储参数,如-Xmx(最大堆大小)和-XX:MaxPermSize。我运行Sun的1.6 jvm。



如果你想知道为什么我想这样做,我有一些JVM webservers可能或可能不会正确配置我想添加到启动代码检查。对于我来说,检查一个java代码更容易部署到任何地方,而不是手动查找和检查所有的jvm启动文件。现在,jvm配置文件不是我们的构建过程或检查源代码控制的一部分。

解决方案

  import java.lang.management.ManagementFactory; 
import java.lang.management.RuntimeMXBean;

import java.util.List;

public void runtimeParameters(){
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
List< String> aList = bean.getInputArguments();

for(int i = 0; i System.out.println(aList.get(i));
}
}

这将显示所有JVM参数。



注意:我们在VCS中没有JVM参数,但在数据库中,由我们自己的发射器在生产中读取。这样,我们可以远程更改这些值,而无需重新部署JVM参数文件设置。






各种 JVM工具用于本文(来自Dustin的软件开发概念和猜测),包括
Java应用程序启动器链接到: / p>




此技术利用了平台MXBeans的优势,因为 J2SE 5 (在 Java SE 6 中添加了自定义MXBeans支持)。



在使用Sun的JVM时,有关JVM参数的两个有用信息源是:





这两个资源列出并描述了一些/所有不推荐的$ c> X 参数( -XX )。



I'm trying to figure out if there's a way to determine the JVM startup properties from within a running java process. Specifically I'm trying to find out where parameters such as -Xmx (max heap size) and -XX:MaxPermSize are stored. I'm running Sun's 1.6 jvm.

If you're wondering why I want to do this, I have a number of JVM webservers that may or may not be configured correctly and I want to add this to the startup code check. It's much easier for me to check in a piece of java code that gets deployed everywhere than to manually find and check all of the jvm startup files. Right now the jvm configuration files for better or worse are not part of our build process or checked into source control.

解决方案

Try:

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

import java.util.List;

public void runtimeParameters() {
  RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
  List<String> aList = bean.getInputArguments();

  for (int i = 0; i < aList.size(); i++) {
    System.out.println( aList.get( i ) );
  }
}

That should show all JVM parameters.

Note: we do not have JVM parameter in VCS either, but in a database, read by our own launchers in productions. That way, we can change those values remotely, without having to redeploy JVM parameter file settings.


You will find a good sumary of various JVM tools to use in this article (from the "Dustin's Software Development Cogitations and Speculations"), including Java Application Launcher links to :

This technique takes advantage of Platform MXBeans available since J2SE 5 (custom MXBeans support was added in Java SE 6).

Two useful sources of information on the JVM parameters available when using Sun's JVM are:

Both of these resources list and describe some/all of the not-recommended-for-the-casual-developer double X arguments (-XX) that are available.

这篇关于读取Java JVM启动参数(例如-Xmx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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