void () { final SynchronizationBasedSemaphore s = new SynchronizationBasedSemaphore(); s.down(); final InvokeThread.WorkerThreadRequest request = getDebugProcess().getManagerThread().getCurrentRequest(); final Thread thread = new Thread("Joining " + request) { @Override public void run() { try { request.join(); } catch (Exception ignored) { } } }; thread.start(); if (request.isDone()) { thread.interrupt(); } waitFor(() -> { try { thread.join(); } catch (InterruptedException ignored) { } }); invokeRatherLater(new DebuggerCommandImpl() { @Override protected void action() { LOG.assertTrue(false); } @Override protected void commandCancelled() { //We wait for invokeRatherLater's invokeRatherLater(new DebuggerCommandImpl() { @Override protected void action() { LOG.assertTrue(false); } @Override protected void commandCancelled() { s.up(); } }); } }); waitFor(s::waitFor); myCompilerManager = (CompilerManagerImpl)CompilerManager.getInstance(getProject()); myCompilerManager.waitForExternalJavacToTerminate(1, TimeUnit.MINUTES); }