线程池(七)线程池手写改造和决绝

public static void main(String[] args) {
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
            2, 5,1L
            , TimeUnit.SECONDS
            , new LinkedBlockingDeque(3)
            , Executors.defaultThreadFactory()
            , new ThreadPoolExecutor.DiscardPolicy()
    );
    try {
        for (int i = 0; i <12; i++) {
            threadPool.execute(()->{ System.out.println(Thread.currentThread().getName()+"\t"+"办理业务"); });
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        threadPool.shutdown();
    }
}

你可能感兴趣的:(线程池(七)线程池手写改造和决绝)