码迷,mamicode.com
首页 > 移动开发 > 详细

Android线程池的使用(未完)

时间:2015-11-15 12:09:30      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:



ExecutorService



Executors
public class Executors

 



// 创建一个线程池,使用固定数量的线程操作共享无界队列。

    public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                                      0L, TimeUnit.MILLISECONDS,
                                      new LinkedBlockingQueue<Runnable>());
    }

 

// 创建一个线程池,它可以在需要的时候创建新的线程,但有线程可用的时候,可以重用以前构建的线程。
// 这个线程池 将会显著提高 许多执行异步任务的 短命线程的 性能
    public static ExecutorService newCachedThreadPool() {
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                                      60L, TimeUnit.SECONDS,
                                      new SynchronousQueue<Runnable>());
    }

 


ThreadPoolExecutor

Android线程池的使用(未完)

标签:

原文地址:http://www.cnblogs.com/carlo/p/4966318.html

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