Discuss / Java / 创建指定动态范围的线程池,报错。

创建指定动态范围的线程池,报错。

Topic source

Loading...

#1 Created at ... [Delete] [Delete and Lock User]

main方法

        ExecutorService es = new ThreadPoolExecutor(0, 4,
                60l, TimeUnit.SECONDS, new SynchronousQueue<>());
        for (int i = 0; i < 6; i++) {
            es.submit(new Task(i));
        }
        es.shutdown();

执行任务

class Task implements Runnable {
    private int i;

    public Task(int i) {
        this.i = i;
    }

    @Override
    public void run() {
        try {
            System.out.println("task " + i);
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }
}

百度了一下,ThreadPoolExecutor的4种拒绝策略,只知其一不知其二,先这样吧。廖大什么时候能把emoji加上就好了。(*^_^*)


  • 1

Reply