• 线程池


    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>


  • 相关阅读:
    48. Rotate Image
    83. Remove Duplicates from Sorted List
    46. Permutations
    HTML5笔记
    18. 4Sum
    24. Swap Nodes in Pairs
    42. Trapping Rain Water
    Python modf() 函数
    Python min() 函数
    Python max() 函数
  • 原文地址:https://www.cnblogs.com/rayallenbj/p/9137949.html
Copyright © 2020-2023  润新知