zoukankan      html  css  js  c++  java
  • 浅谈线程池ThreadPoolExecutor核心参数

    public ThreadPoolExecutor(
                              int corePoolSize,                //核心池的大小。
                              int maximumPoolSize,                    //池中允许的最大线程数,这个参数表示了线程池中最多能创建的线程数量
                              long keepAliveTime,               //当线程数大于corePoolSize时,终止前多余的空闲线程等待新任务的最长时间
                              TimeUnit unit,                 //keepAliveTime时间单位
                              BlockingQueue<Runnable> workQueue,    //存储还没来得及执行的任务
                              ThreadFactory threadFactory,      //执行程序创建新线程时使用的工厂
                              RejectedExecutionHandler handler   //由于超出线程范围和队列容量而使执行被阻塞时所使用的处理程序
    )       
    

    corePoolSize与maximumPoolSize举例理解

    1、池中线程数小于corePoolSize,新任务都不排队而是直接添加新线程

    2、池中线程数大于等于corePoolSize,workQueue未满,首选将新任务加入workQueue而不是添加新线程

    3、池中线程数大于等于corePoolSize,workQueue已满,但是线程数小于maximumPoolSize,添加新的线程来处理被添加的任务

    4、池中线程数大于大于corePoolSize,workQueue已满,并且线程数大于等于maximumPoolSize,新任务被拒绝,使用handler处理被拒绝的任务

  • 相关阅读:
    微信小程序の模板
    微信小程序の条件渲染
    微信小程序のwxml列表渲染
    769. Max Chunks To Make Sorted
    766. Toeplitz Matrix
    747. Largest Number At Least Twice of Others
    746. Min Cost Climbing Stairs
    729. My Calendar I
    724. Find Pivot Index
    718. Maximum Length of Repeated Subarray
  • 原文地址:https://www.cnblogs.com/stupid-chan/p/9991307.html
Copyright © 2011-2022 走看看