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

    ThreadPoolExecutor
    1、线程池5个运行状态
    RUNNING: Accept new tasks and process queued tasks
    SHUTDOWN: Don't accept new tasks, but process queued tasks
    STOP:     Don't accept new tasks, don't process queued and interrupt in-progress tasks
    TIDYING: All tasks have terminated, workerCount is zero, the thread transitioning to state TIDYING will run the terminated() hook method
    TERMINATED: terminated() has completed

     RUNNING -> SHUTDOWN
    On invocation of shutdown(), perhaps implicitly in finalize()
    (RUNNING or SHUTDOWN) -> STOP
    On invocation of shutdownNow()
    SHUTDOWN -> TIDYING
    When both queue and pool are empty
    STOP -> TIDYING
    When pool is empty
    TIDYING -> TERMINATED
    When the terminated() hook method has completed
    2、几个重要属性
    corePoolSize、maximumPoolSize、threadFactory、keepAliveTime、workQueue.
    When a new task is submitted in method {@link #execute(Runnable)},  
    and fewer than corePoolSize threads are running, a new thread is
    created to handle the request, even if other worker threads are
    idle. If there are more than corePoolSize but less than
    maximumPoolSize threads running, a new thread will be created only
    if the queue is full. By setting corePoolSize and maximumPoolSize
    the same, you create a fixed-size thread pool. By setting
    maximumPoolSize to an essentially unbounded value such as {@code
    Integer.MAX_VALUE}, you allow the pool to accommodate an arbitrary
    number of concurrent tasks. Most typically, core and maximum pool
    sizes are set only upon construction, but they may also be changed
    dynamically using {@link #setCorePoolSize} and {@link
    #setMaximumPoolSize}. </dd>


  • 相关阅读:
    Python流程控制
    Python 迭代器和列表解析
    Python 文件对象
    TF-IDF介绍
    hexo博客更换主题
    学习笔记—MapReduce
    Mac下Anaconda的安装和使用
    Flume的介绍和简单操作
    hexo+github搭建个人博客
    Hbase的安装和基本使用
  • 原文地址:https://www.cnblogs.com/rayallenbj/p/9137949.html
Copyright © 2011-2022 走看看