void () { Set<Thread> used = ConcurrentCollectionFactory.createConcurrentSet(); AtomicInteger executed = new AtomicInteger(); int N = 100000; List<Alarm> alarms = Stream.generate(() -> new Alarm(getTestRootDisposable())).limit(N).toList(); alarms.forEach(alarm -> alarm.addRequest(() -> { executed.incrementAndGet(); used.add(Thread.currentThread()); }, 10)); while (executed.get() != N) { UIUtil.dispatchAllInvocationEvents(); } if (used.size() > 10) { fail(used.size()+" threads created: "+used.stream().map(t->PerformanceWatcher.printStacktrace("", t, t.getStackTrace())).collect(Collectors.joining())); } }