ThreadPoolExecutor五种线程池状态(runState)

发布时间 2023-06-14 10:03:38作者: 懒阳阳是小学生

 

    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 tasks, 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



    private static final int COUNT_BITS = Integer.SIZE - 3;
    // runState is stored in the high-order bits
    private static final int RUNNING    = -1 << COUNT_BITS;
    private static final int SHUTDOWN   =  0 << COUNT_BITS;
    private static final int STOP       =  1 << COUNT_BITS;
    private static final int TIDYING    =  2 << COUNT_BITS;
    private static final int TERMINATED =  3 << COUNT_BITS;