-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountDownLatch.java
More file actions
33 lines (23 loc) · 794 Bytes
/
Copy pathCountDownLatch.java
File metadata and controls
33 lines (23 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.concurrent.*;
public class CountDownLatchWithExecutor {
public static void main(String[] args) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(3);
CountDownLatch latch = new CountDownLatch(3);
executor.submit(() -> {
System.out.println("DB Service Ready");
latch.countDown();
});
executor.submit(() -> {
System.out.println("Email Service Ready");
latch.countDown();
});
executor.submit(() -> {
System.out.println("Cache Service Ready");
latch.countDown();
});
// main thread waits
latch.await();
System.out.println("Application Started");
executor.shutdown();
}
}