void () { AtomicBoolean finished = new AtomicBoolean(); Runnable action = () -> { TestTimeOut t = TestTimeOut.setTimeout(10, TimeUnit.SECONDS); while (!finished.get()) { ProgressManager.checkCanceled(); if (t.timedOut()) { finished.set(true); throw new AssertionError("Too long without cancellation"); } } }; List<Future<?>> futures = new ArrayList<>(); for (int i = 0; i < 3; i++) { futures.add(ApplicationManager.getApplication().executeOnPooledThread(() -> { while (!finished.get()) { ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(action); } })); futures.add(ApplicationManager.getApplication().executeOnPooledThread(() -> { ProgressIndicatorBase reusableProgress = new ProgressIndicatorBase(true); while (!finished.get()) { ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(action, reusableProgress); } })); futures.add(ReadAction.nonBlocking(action).submit(AppExecutorUtil.getAppExecutorService())); } for (int i = 0; i < 10_000 && !finished.get(); i++) { UIUtil.dispatchAllInvocationEvents(); WriteAction.run(() -> {}); } finished.set(true); waitForFutures(futures); }