-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemaphoreApp.java
More file actions
34 lines (27 loc) · 928 Bytes
/
SemaphoreApp.java
File metadata and controls
34 lines (27 loc) · 928 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
34
package examples8;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class SemaphoreApp {
// public static void main(String[] args) throws Exception {
// Semaphore sem = new Semaphore(1);
// System.out.println("Available permits: " + sem.availablePermits());
// sem.release();
// System.out.println("Available permits: " + sem.availablePermits());
// sem.acquire();
// System.out.println("Available permits: " + sem.availablePermits());
// }
public static void main(String[] args) throws Exception {
ExecutorService service = Executors.newCachedThreadPool();
for (int i = 0; i < 200; i++) {
service.submit(new Runnable() {
@Override
public void run() {
Connection.getInstance().connect();
}
});
}
service.shutdown();
service.awaitTermination(1, TimeUnit.DAYS);
}
}