简体   繁体   English

在JVM中以编程方式设置-X和-XX:系统属性

[英]Programmatically Set -X: and -XX: System Properties in JVM

I know The -D properties can be set by System.setProperty() which takes the key=>value form. 我知道-D属性可以通过采用key => value形式的System.setProperty()进行设置。

But how do I set the -XX options. 但是,如何设置-XX选项。 I'm specifically looking to set -XX:+PrintGCDetails inside main(); 我特别想在main();中设置-XX:+ PrintGCDetails;

You can't change that once the JVM has started. JVM启动后就无法更改。 These are not Java system properties, but parameters that govern the startup and configuration of the JVM system. 这些不是Java系统属性,而是控制JVM系统的启动和配置的参数。

The only way to set these values is to start another Java process. 设置这些值的唯一方法是启动另一个Java进程。 You can start a new process with the parameters you want and exit. 您可以使用所需的参数启动新过程并退出。 You can't change the options once the process has started. 该过程开始后,您将无法更改选项。

If you are launching a java applet you can pass them in a parameter called java_arguments. 如果要启动Java小程序,则可以在名为java_arguments的参数中传递它们。

If you are launching a JNLP program you can pass the parameters like this: 如果要启动JNLP程序,则可以传递如下参数:

<resources>
    <jar href="MyApp.jar" />
    <java version="1.6+" initial-heap-size="5m" max-heap-size="256m" java-vm-args="-XXSomeOption" />
</resources>

You cannot change these parameters once the application is running, but you can re-launch java by looking at system properties like java.home to determine which JVM was used to launch your program. 一旦应用程序运行,就无法更改这些参数,但是可以通过查看java.home之类的系统属性来重新启动Java,以确定使用哪个JVM启动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM