-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.java
More file actions
43 lines (31 loc) · 831 Bytes
/
pool.java
File metadata and controls
43 lines (31 loc) · 831 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
35
36
37
38
39
40
41
42
43
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class pool {
/**
* @param args
*/
public static void main(String[] args) {
Thread thread1 = new executor("a");
Thread thread2 = new executor("b");
Thread thread3 = new executor("c");
Thread thread4 = new executor("d");
Thread thread5 = new executor("e");
ExecutorService pool = Executors.newFixedThreadPool(5);
pool.execute(thread1);
pool.execute(thread2);
pool.execute(thread3);
pool.execute(thread4);
pool.execute(thread5);
pool.shutdown();
}
static class executor extends Thread {
private final String name;
public executor(String name) {
this.name = name;
}
@Override
public void run() {
System.out.println("i am executed in executor pool : " + name);
}
}
}