void (int timeout, @NotNull TimeUnit unit) { long start = System.currentTimeMillis(); while (System.currentTimeMillis() < start + unit.toMillis(timeout)) { Thread jdiThread = ContainerUtil.find(ThreadLeakTracker.getThreads().values(), thread -> { ThreadGroup group = thread.getThreadGroup(); return group != null && group.getParent() != null && "JDI main".equals(group.getParent().getName()); }); if (jdiThread == null) { break; } try { long timeLeft = start + unit.toMillis(timeout) - System.currentTimeMillis(); LOG.debug("Waiting for the "+jdiThread+" for " + timeLeft+"ms"); jdiThread.join(timeLeft); } catch (InterruptedException e) { throw new RuntimeException(e); } } }