使用ThreadFactoryBuilder来创建线程池

375 阅读1分钟

本文章主要介绍了使用ThreadFactoryBuilder来创建线程池,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!

使用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());
    }
}