首页 新闻 赞助 找找看

关于ThreadPoolExecutor 拒绝任务

0
[待解决问题]
public static void main(String... args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 60 * 10L,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(2), new ThreadPoolExecutor.AbortPolicy());
        List<Future> futures = new ArrayList<>();
        System.out.println("main:" + Thread.currentThread().getName());
        for (int i = 0; i < 20; i++) {
            try {
                futures.add(executor.submit(new Test.Worker(i)));
            } catch (Exception e) {
                System.out.println("what's the fuck");
            }
            if (futures.size() > 2) {
                for (Future future : futures) {
                    future.get();
                }
                futures.clear();
            }
        }
        for (Future future : futures) {
            future.get();
        }
        executor.shutdown();
    }

按照道理,增加的任务不会达到 maxPoolSize 和 queue 之和,“whats the ***”应该是不会执行,但是 通过IDE run的时候还是会走到,但是 debug 却不会执行到该语句。绞尽脑汁不得解,还望哪位大神解答。

爬行的主页 爬行 | 菜鸟二级 | 园豆:202
提问于:2019-07-03 14:34
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册