--- +++ Fri May 04 15:33:27 2012 +0200 @@ -60,6 +60,8 @@ import java.net.*; import java.text.MessageFormat; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; /** @@ -373,6 +375,7 @@ private static volatile boolean detachCommandReceived; private static ProfilerServer profilerServer; private static ProfilingSessionStatus status; + private static boolean activated = false; private static volatile boolean startTargetApp; private static volatile boolean targetAppMainThreadComplete; private static volatile Exception startupException; @@ -916,6 +919,25 @@ } status.targetAppRunning = true; + setActivatedFlag(); + } + + private static synchronized void setActivatedFlag() { + activated = true; + ProfilerServer.class.notifyAll(); + } + + /** + * Waits till the server gets activated; eg. all internals are initialised + */ + public static synchronized void waitActivated() { + while (!activated && !Thread.currentThread().isInterrupted()) { + try { + ProfilerServer.class.wait(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } } private static void forcedShutdown() { --- a/lib.profiler/src/org/netbeans/lib/profiler/server/SamplingThread.java Fri May 04 12:22:45 2012 +0200 +++ a/lib.profiler/src/org/netbeans/lib/profiler/server/SamplingThread.java Fri May 04 15:33:27 2012 +0200 @@ -38,6 +38,8 @@ } public void run() { + ProfilerServer.waitActivated(); // #205344: Wait for the profiler engine to get activated; prevents appearing profiler methods on stack sample + int adjustedSamplingInterval = samplingInterval; int upperBound = (samplingInterval * 5) / 4; int lowerBound = samplingInterval / 10;