forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPoolExecutorDemo.java
More file actions
38 lines (35 loc) · 1.07 KB
/
ThreadPoolExecutorDemo.java
File metadata and controls
38 lines (35 loc) · 1.07 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
37
38
/**
* @program JavaBooks
* @description: ThreadPoolExecutorDemo
* @author: mf
* @create: 2020/02/17 00:37
*/
package com.juc.pool;
import java.util.concurrent.*;
public class ThreadPoolExecutorDemo {
public static void main(String[] args) {
ExecutorService threadpools = new ThreadPoolExecutor(
3,
5,
1l,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(3),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy());
//new ThreadPoolExecutor.AbortPolicy();
//new ThreadPoolExecutor.CallerRunsPolicy();
//new ThreadPoolExecutor.DiscardOldestPolicy();
//new ThreadPoolExecutor.DiscardPolicy();
try {
for (int i = 0; i < 8; i++) {
threadpools.execute(() -> {
System.out.println(Thread.currentThread().getName() + "\t办理业务");
});
}
} catch (Exception e) {
e.printStackTrace();
} finally {
threadpools.shutdown();
}
}
}