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>


  • 相关阅读:
    R语言入门心得(1) -- 下载与安装
    ASP.NET中ListView用DataPager分页
    .Net平台下的扩展方法
    疑问句
    时态
    webapi put 404
    记一次阿里云ECS服务器图片资源迁移至 阿里云 oss
    javascript
    阿里云 oss 上传文件,js直传,.net 签名,回调
    redis 持久化共享 Session
  • 原文地址:https://www.cnblogs.com/rayallenbj/p/9137949.html
Copyright © 2011-2022 走看看