zoukankan      html  css  js  c++  java
  • Java线程池

    java.util.concurrent包

    接口及相关类的继承关系:

    interface: Executor - ExecutorService - ScheduledExecutorService

    subclass: ThreadPoolExecutor - ScheduledThreadPoolExecutor

    Executor

      |-ExecutorService <- ThreadPoolExecutor

        |-ScheduledExecutorService <- ScheduledThreadPoolExecutor

    由于ThreadPoolExecutor和ScheduledThreadPoolExecutor构造函数过于复杂,因此使用类Executors对其进行默认设置

    Executors内部有五个产生线程池的工厂方法(方法内部对ThreadPoolExecutor和ScheduledThreadPoolExecutor的参数进行默认设置):

    1. newCachedThreadPool()

      无界线程池:有任务时创建新线程,空闲线程保留60s自动回收

    2. newFixedThreadPool()

      固定大小线程池:空闲保留,若任务超出线程池大小则等待

    3. newSingleThreadExecutor()

      只有一个工作线程,依次执行任务

    4. newScheduledThreadPool()

      按时间计划进行任务的单个工作线程

    5. newSingleScheduledExecutor()

      按时间计划(定时、周期任务)进行任务的线程池

  • 相关阅读:
    shell基础命令
    UITest 单元测试常用的断言
    UIColor 使用起来的坑
    appledoc 使用brew命令安装使用
    appledoc 使用
    Xcode升级 Alcatraz 无法使用
    APP多语言环境支持
    VVDocumenter 使用
    NSDate NSString相互转化
    iOS 常见设计模式
  • 原文地址:https://www.cnblogs.com/joshua-aw/p/6017834.html
Copyright © 2011-2022 走看看