void (@NotNull ProcessHandler processHandler) { Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getTestRootDisposable()); AtomicBoolean isRunning = new AtomicBoolean(true); alarm.addRequest(() -> { if (isRunning.get()) { processHandler.destroyProcess(); LOG.error("process was running over " + myTimeoutMillis / 1000 + " seconds. Interrupted. "); } }, myTimeoutMillis); processHandler.waitFor(); isRunning.set(false); Disposer.dispose(alarm); }