-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathExecutorException.java
More file actions
49 lines (42 loc) · 1.24 KB
/
ExecutorException.java
File metadata and controls
49 lines (42 loc) · 1.24 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
39
40
41
42
43
44
45
46
47
48
49
package concurrent;
import java.util.concurrent.*;
/**
* @author vonzhou
* @date 2018/12/4
*/
public class ExecutorException {
static ExecutorService executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<Runnable>(1000), new ThreadFactory() {
private int counter = 0;
private String prefix = "Worker";
@Override
public Thread newThread(Runnable r) {
return new Thread(r, prefix + "-" + counter++);
}
}, new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
try {
executor.getQueue().put(r);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
public static void main(String[] args) {
try {
executor.submit(new Runnable() {
@Override
public void run() {
process();
}
});
} catch (Exception e) {
e.printStackTrace();
}
executor.shutdown();
}
private static void process() {
throw new RuntimeException("fake error");
}
}