美文网首页
线程池(七)线程池手写改造和决绝

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

作者: 香山上的麻雀 | 来源:发表于2020-02-07 09:51 被阅读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();
    }
}

相关文章

网友评论

      本文标题:线程池(七)线程池手写改造和决绝

      本文链接:https://www.haomeiwen.com/subject/gvxmxhtx.html