forked from zhaoshiling1017/ThreadProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyExecutor.java
More file actions
36 lines (31 loc) · 1.03 KB
/
Copy pathMyExecutor.java
File metadata and controls
36 lines (31 loc) · 1.03 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
35
36
package com.unicss;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class MyExecutor extends Thread {
private int index;
public MyExecutor(int i) {
this.index = i;
}
@Override
public void run() {
try {
System.out.println("[" + this.index + "] start....");
Thread.sleep((int) (Math.random() * 10000));
System.out.println("[" + this.index + "] end.");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
ExecutorService executorService = Executors.newFixedThreadPool(4);
for (int i = 0; i < 10; i++) {
//void execute(Runnable command);
executorService.execute(new MyExecutor(i));
// Future<?> submit(Runnable task);
// executorService.submit(new MyExecutor(i));
}
System.out.println("submit finish");
executorService.shutdown();
}
}