如何从 Java 应用程序内部获取 VM 参数? [英] How to get VM arguments from inside of Java application?

查看:33
本文介绍了如何从 Java 应用程序内部获取 VM 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查某些可以传递给 JVM 的选项是否已显式设置或具有其默认值.

I need to check if some option that can be passed to JVM is explicitly set or has its default value.

更具体地说:我需要创建一个具有比默认堆栈更大的本机堆栈大小的特定线程,但是如果用户想要通过指定 -Xss 选项自己处理这些事情,我想创建所有线程使用默认堆栈大小(将由用户在 -Xss 选项中指定).

To be more specific: I need to create one specific thread with higher native stack size than the default one, but in case the user wants to take care of such things by himself by specifying the -Xss option I want to create all threads with default stack size (which will be specified by user in -Xss option).

我已经检查了诸如 java.lang.Systemjava.lang.Runtime 之类的类,但是这些并没有给我任何关于 VM 参数的有用信息.

I've checked classes like java.lang.System and java.lang.Runtime, but these aren't giving me any useful information about VM arguments.

有什么方法可以获得我需要的信息吗?

Is there any way to get the information I need?

推荐答案

使用此代码您可以获得 JVM 参数:

With this code you can get the JVM arguments:

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
...
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();

这篇关于如何从 Java 应用程序内部获取 VM 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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