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

2020-02-07  本文已影响0人  香山上的麻雀
public static void main(String[] args) {
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
            2, 5,1L
            , TimeUnit.SECONDS
            , new LinkedBlockingDeque<Runnable>(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();
    }
}
上一篇 下一篇

猜你喜欢

热点阅读