Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is an answer to the secondary question, "How can you tell if the -XstartOnFirstThread argument is actually being read by the VM?" (or the related question, "how can you detect if -XstartOnFirstThread was passed to the VM?") I looked at <code>java.lang.management.RuntimeMXBean.getInputArguments()</code>, but <code>-XstartOnFirstThread</code> is <em>not</em> included in the returned <code>List</code>. After some research, I was able to figure out something, so I hope this helps someone else who was in my shoes.</p> <p>According to <a href="http://bugs.sun.com/view_bug.do?bug_id=7131021" rel="nofollow">this link</a>, there are several environment variables set by the launcher. Among them are: <code><pre>JAVA_MAIN_CLASS_<em>pid</em> JAVA_STARTED_ON_FIRST_THREAD_<em>pid</em></pre></code></p> <p>Use <code>System.getenv()</code> to obtain a <code>Map</code> of the environment variables. From there, you can iterate through the <code>entrySet()</code> until you find an <code>Entry</code> with a <code>getKey()</code> whose return value starts with <code>"JAVA_MAIN_CLASS_"</code> . If the discovered <code>Entry</code>'s <code>getValue()</code> contains the name of your main class, you can use the rest of the key to determine the <em>pid</em>.</p> <p>Once you have the <em>pid</em>, look up the string <code>"JAVA_STARTED_ON_FIRST_THREAD_<em>pid</em>"</code> in the environment <code>Map</code>. If it exists and has the value <code>"1"</code>, the process was started with <code>-XstartOnFirstThread</code>. Otherwise, the process was started without the flag.</p> <p>This probably won't work in an unsigned WebStart application, since the <code>System.getenv()</code> method is prohibited by default. But in a signed webstart application, or in a regular Java application, this does work.</p> <p>Hope that helps,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload