-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread5.java
More file actions
34 lines (32 loc) · 1 KB
/
Copy pathThread5.java
File metadata and controls
34 lines (32 loc) · 1 KB
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
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class WorkerThread implements Runnable {
private String name;
public WorkerThread(String name) {
this.name = name;
}
public void run() {
System.out.println(Thread.currentThread().getName() + " (Start) : " + name);
processmanager();
System.out.println(Thread.currentThread().getName() + " (end)");
}
private void processmanager() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
public class Thread5 {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i < 10; i++) {
Runnable worker = new WorkerThread("" + i);
executor.execute(worker);
}
executor.shutdown();
while (!executor.isTerminated()) {}
System.out.println("Finished all threads");
}
}