码迷,mamicode.com
首页 > 编程语言 > 详细

为什么要用Executors.defaultThreadFactory().newThread(run);创建线程?

时间:2016-07-02 20:12:09      阅读:1132      评论:0      收藏:0      [点我收藏+]

标签:

Executors

/**
     * Creates a thread pool that reuses a fixed number of threads
     * operating off a shared unbounded queue.  At any point, at most
     * {@code nThreads} threads will be active processing tasks.
     * If additional tasks are submitted when all threads are active,
     * they will wait in the queue until a thread is available.
     * If any thread terminates due to a failure during execution
     * prior to shutdown, a new one will take its place if needed to
     * execute subsequent tasks.  The threads in the pool will exist
     * until it is explicitly {@link ExecutorService#shutdown shutdown}.
     *
     * @param nThreads the number of threads in the pool
     * @return the newly created thread pool
     * @throws IllegalArgumentException if {@code nThreads <= 0}
     */
    public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                                      0L, TimeUnit.MILLISECONDS,
                                      new LinkedBlockingQueue<Runnable>());
    }
}

private ExecutorService proThreadPool = Executors.newFixedThreadPool(50);

 

为什么要用Executors.defaultThreadFactory().newThread(run);创建线程?

标签:

原文地址:http://www.cnblogs.com/xxdfly/p/5635907.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!