ITPub博客

首页 > 应用开发 > Java > 各种线程池实现,pool

各种线程池实现,pool

Java 作者:xz43 时间:2016-03-15 17:00:51 0 删除 编辑

列举几种线程池实现:

【1】ExecutorService

http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ExecutorService.html

【2】ScheduledExecutorService

http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ScheduledExecutorService.html

【3】ThreadPoolExecutor

http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ThreadPoolExecutor.html

【4】ScheduledThreadPoolExecutor

http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ScheduledThreadPoolExecutor.html

 

 

public static void main(String[] args) {
 
    // 创建一个可重用固定线程集合的线程池,以共享的无界队列(a shared unbounded queue)方式来运行这些线程
    ExecutorService pool1 = Executors.newFixedThreadPool(3);
    
    // 创建一个可根据需要创建新线程的线程池,但是在以前构造的线程可用时将重用它们
    ExecutorService pool2 = Executors.newCachedThreadPool();
 
    // 创建一个使用单个worker线程的Executor,以无界队列方式来运行该线程
    ExecutorService pool3 = Executors.newSingleThreadExecutor();
 
    // 创建一个线程池,它可安排在给定延迟后运行命令或者定期地执行
    ScheduledExecutorService pool4 = Executors.newScheduledThreadPool(3);
 
    // 创建一个单线程执行程序,它可安排在给定延迟后运行命令或者定期地执行
    ScheduledExecutorService pool5 = Executors.newSingleThreadScheduledExecutor();
 
    // 创建一个可伸缩线程池
    ThreadPoolExecutor pool6 = new ThreadPoolExecutor(3, 5, 3,
            TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3), new ThreadPoolExecutor.DiscardOldestPolicy());
 
    // 创建一个可伸缩线程池,它可安排在给定延迟后运行命令或者定期地执行
    ScheduledThreadPoolExecutor pool7 = new ScheduledThreadPoolExecutor(5);
    
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9399028/viewspace-2057742/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Log4j 配置详解
请登录后发表评论 登录
全部评论
鱼儿的学习空间

注册时间:2010-11-16

  • 博文量
    433
  • 访问量
    1863763