forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT26.java
More file actions
28 lines (24 loc) · 727 Bytes
/
T26.java
File metadata and controls
28 lines (24 loc) · 727 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
package com.basic;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @program JavaBooks
* @description: 第三种,single
* @author: mf
* @create: 2020/01/01 14:56
*/
/**
* 尽管是线程池中的单个线程,但是比那种每次创建个线程,系统开销大的稍微好点。。。
*/
public class T26 {
public static void main(String[] args) {
ExecutorService service = Executors.newSingleThreadExecutor();
for (int i = 0; i < 5; i++) {
final int j = i;
service.execute(() -> {
System.out.println(j + " " + Thread.currentThread().getName());
});
}
service.shutdown();
}
}