-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRejectMainV4.java
More file actions
28 lines (23 loc) · 949 Bytes
/
Copy pathRejectMainV4.java
File metadata and controls
28 lines (23 loc) · 949 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 thread.executor.reject;
import thread.executor.RunnableTask;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import static util.MyLogger.log;
public class RejectMainV4 {
public static void main(String[] args) {
ExecutorService es = new ThreadPoolExecutor(1,1,0, TimeUnit.SECONDS,
new SynchronousQueue<>(), new MyRejectedExecutionHandler());
es.submit(new RunnableTask("task1"));
es.submit(new RunnableTask("task2"));
es.submit(new RunnableTask("task3"));
es.shutdown();
}
static class MyRejectedExecutionHandler implements RejectedExecutionHandler {
static AtomicInteger count = new AtomicInteger(0);
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
int i = count.incrementAndGet();
log("[경고] 거잘된 누적 작업 수 : " + i);
}
}
}