Accessing VM Arguments from Within Java
Question:
How can I determine if a specific JVM option was explicitly set or left with its default value from within a Java application? Specifically, I require the ability to create a thread with a custom native stack size. However, if the user has specified the "-Xss" option, I need to revert to the default stack size.
Answer:
To access VM arguments inside your Java code, employ the following strategy:
During startup, pass the desired option using the "-D" flag:
-Dname=value
Within your code, retrieve the specified value using the "System.getProperty()" method:
value = System.getProperty("name");
By utilizing this approach, you can readily check whether a specific JVM option has been explicitly set or defaults to its standard value.
The above is the detailed content of How to Determine if a JVM Option was Set from Within a Java Application?. For more information, please follow other related articles on the PHP Chinese website!