Вы можете использовать CountDownLatch
для достижения того, что вы пытаетесь;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TestApp {
private static final int THREAD_COUNT = 10;
public static void main(String... args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
final CountDownLatch countDownLatch = new CountDownLatch(THREAD_COUNT);
for(int i=0;i<THREAD_COUNT;i++) {
executorService.execute(() -> {
countDownLatch.countDown();
try {
countDownLatch.await();
System.out.println(Thread.currentThread().getName() + " - " + System.currentTimeMillis());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
}
}
}
Результат
pool-1-thread-5 - 1586432194060
pool-1-thread-8 - 1586432194060
pool-1-thread-4 - 1586432194060
pool-1-thread-6 - 1586432194060
pool-1-thread-1 - 1586432194060
pool-1-thread-2 - 1586432194060
pool-1-thread-9 - 1586432194060
pool-1-thread-3 - 1586432194060
pool-1-thread-7 - 1586432194060
pool-1-thread-10 - 1586432194060