private void notifyTerminated(final int exitCode, final boolean willBeDestroyed) {
    myAfterStartNotifiedRunner.execute(() -> {
      LOG.assertTrue(isStartNotified(), "Start notify is not called");

      if (myState.compareAndSet(State.RUNNING, State.TERMINATING)) {
        try {
          fireProcessWillTerminate(willBeDestroyed);
        }
        catch (Throwable e) {
          if (!isCanceledException(e)) {
            LOG.error(e);
          }
        }
      }

      if (myState.compareAndSet(State.TERMINATING, State.TERMINATED)) {
        try {
          myExitCode = exitCode;
          myEventMulticaster.processTerminated(new ProcessEvent(this, exitCode));
        }
        catch (Throwable e) {
          if (!isCanceledException(e)) {
            LOG.error(e);
          }
        }
        finally {
          myWaitSemaphore.up();
        }
      }
    });
  }
private void notifyTerminated(final int exitCode, final boolean willBeDestroyed)