5、线程池之ct1和workerCountOf
作者:
kele2018 | 来源:发表于
2020-03-17 13:26 被阅读0次private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));//-536870912
private static final int COUNT_BITS = Integer.SIZE - 3;
private static final int RUNNING = -1 << COUNT_BITS; //-1向左移动29位 1110 0000 0000 0000 0000 0000 0000 0000
private static final int SHUTDOWN = 0 << COUNT_BITS; // 0000 0000 0000 0000 0000 0000 0000 0000
private static final int STOP = 1 << COUNT_BITS; //0010 0000 0000 0000 0000 0000 0000 0000
private static final int TIDYING = 2 << COUNT_BITS; //0100 0000 0000 0000 0000 0000 0000 0000
private static final int TERMINATED = 3 << COUNT_BITS;//0110 0000 0000 0000 0000 0000 0000 0000
/**
CAPACITY:00011111111111111111111111111111
~CAPACITY:11100000000000000000000000000000
**/
private static final int CAPACITY = (1 << COUNT_BITS) - 1;
private static int ctlOf(int rs, int wc) { return rs | wc; } // | 如果对应位都是0,则为0 否则为1
//取c的低位
private static int workerCountOf(int c) { return c & CAPACITY; } // & 如果对应位都是1,则为1 否则为0
//取c的高位
private static int runStateOf(int c) { return c & ~CAPACITY; }
本文标题:5、线程池之ct1和workerCountOf
本文链接:https://www.haomeiwen.com/subject/rkhtyhtx.html
网友评论