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>


  • 相关阅读:
    My Tornado Particle Effect
    [zz] 海洋环境的光能传递
    一道算法题
    Alembic
    一些莫名其妙的东东
    Python Q&A
    <<Exceptional C++>> notes
    CG Rendering v.s. Browser Rendering
    Modo
    Katana
  • 原文地址:https://www.cnblogs.com/rayallenbj/p/9137949.html
Copyright © 2011-2022 走看看