使用ThreadFactoryBuilder来创建线程池

  • Post author:
  • Post category:其他


使用guava的ThreadFactoryBuilder来创建线程池

public class Demo {

    private static ThreadFactory nameFactory = new ThreadFactoryBuilder()
        .setNameFormat("demo-pool-%d").build();

    private static ExecutorService pool = new ThreadPoolExecutor(5, 200,
        0L, TimeUnit.MILLISECONDS,
        new LinkedBlockingQueue<Runnable>(1024), namedFactory, new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) {

        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            pool.execute(new SubThread());
        }
    }
}



版权声明:本文为fall_hat原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。