5、线程池之ct1和workerCountOf

2020-03-17  本文已影响0人  kele2018
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; }
上一篇 下一篇

猜你喜欢

热点阅读