void (Runnable r) { Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getTestRootDisposable()); Thread thread = Thread.currentThread(); AtomicBoolean isRunning = new AtomicBoolean(true); alarm.addRequest(() -> { if (isRunning.get()) { thread.interrupt(); LOG.error("test was running over " + myTimeoutMillis / 1000 + " seconds. Interrupted. "); } }, myTimeoutMillis); r.run(); isRunning.set(false); Thread.interrupted(); Disposer.dispose(alarm); }