-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
26 lines (22 loc) · 849 Bytes
/
Test.java
File metadata and controls
26 lines (22 loc) · 849 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
package win.sz90.threadpool;
/**
* Created by shawn.zeng on 2018/5/31.
*/
import java.util.stream.IntStream;
public class Test {
public static void main(String[] args) throws InterruptedException {
SimpleThreadPoolExecutor executor = new SimpleThreadPoolExecutor();
IntStream.range(0, 50).forEach(i ->
executor.submit(() -> {
System.out.printf("[线程] - [%s] 开始工作...\n", Thread.currentThread().getName());
try {
Thread.sleep(2_000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.printf("[线程] - [%s] 工作完毕...\n", Thread.currentThread().getName());
})
);
executor.shutdown();
}
}