wen涛 2019-07-03 15:44 采纳率: 0%
浏览 799

关于ThreadPoolExecutor 拒绝任务

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 却不会执行到该语句。绞尽脑汁不得解,还望哪位大神解答。

  • 写回答

2条回答 默认 最新

  • 毕小宝 博客专家认证 2019-07-03 16:49
    关注

    你把堆栈异常打出来,看看最终是什么异常。

    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?