views:

1651

answers:

4

Hello, 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?

A: 

AFAIK, there is no way to get hold of the "vmargs" supplied when the JVM is launched. The exception (of course) is that "-Dname=value" options are available to a Java application in the System Properties object.

Stephen C
A: 

EDIT: I can't see any way to do this either See other answers for how to get this information via JMX.

However, I still suggest you decouple the user's choice of stack size from your decision as to whether to use a non-default stack size? Have that as a separate property, either as a system property or as part of your normal configuration file.

Jon Skeet
A: 

I haven't tried specifically getting the VM settings, but there is a wealth of information in the JMX utilities specifically the MXBean utilities. This would be where I would start. Hopefully you find something there to help you.

The sun website has a bunch on the technology:

http://java.sun.com/javase/6/docs/technotes/guides/management/mxbeans.html

reccles
+8  A: 

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();
David Schuler
Sadly you cannot get the Name of the main class if it is given on the command line.
Daniel