Sunday, July 15, 2012


I need to check if some option which can be passed to JVM is explicitly set or is it have default value.
To be more specific: I need to create one specific thread with higher native stack size than the default one, but in case then user want to take care of such things by himself by specifying -Xss option I want to create all threads with default stack size (which will be specified by user in -Xss option). I've checked classes like java.lang.System and java.lang.Runtime, but these aren't giving me information about vmargs. Is there any way to get information I need?
link|improve this question

80% accept rate
Next time you log in, could you switch the accepted answer? – Erick Robertson Dec 5 '11 at 13:09
feedback

3 Answers

up vote30down voteaccepted
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();
link|improve this answer
Sadly you cannot get the Name of the main class if it is given on the command line. – Daniel May 20 '10 at 8:06
@Daniel, this should get you the name of the main class: final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); final String mainClassName = stackTrace[stackTrace.length - 1].getClassName()); – laz Nov 16 '11 at 18:43
@laz System.getProperty("sun.java.command") is far simpler. – Vulcan May 28 at 6:19
If you are guaranteed to be running on Oracle's JVM and have the code to parse the arguments that can be useful. – laz May 28 at 12:57
feedback
HI try this Pass this "-Dname=value"
and ur code should be doing this value=System.getproperty("name");
Regards ..
link|improve this answer

No comments: