1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package com.sf.threadpool;
- import java.util.concurrent.Callable;
- import java.util.concurrent.LinkedBlockingDeque;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
- public class PolicyTest {
- public static void main(String[] args) {
- ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
- 1, 3, 1024, TimeUnit.SECONDS,
- new LinkedBlockingDeque<>(1), new MyRejectedPolicy());
- threadPoolExecutor.setRejectedExecutionHandler(new MyRejectedPolicy());
- for (int i = 0; i < 5; i++) {
- threadPoolExecutor.execute(() -> {
- try {
- Thread.sleep(100000000L);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- });
- }
- // for (int i = 0; i < 5; i++) {
- // threadPoolExecutor.execute(new Runnable() {
- // @Override
- // public void run() {
- // try {
- // Thread.sleep(100000000L);
- // } catch (InterruptedException e) {
- // throw new RuntimeException(e);
- // }
- // }
- // });
- //
- // threadPoolExecutor.submit(new Callable<String>() {
- // @Override
- // public String call() throws Exception {
- // return "";
- // }
- // });
- // }
- }
- }
|