2017-06-19 5 views

答えて

1

このコードin the source周りにビットを見て:

private static final int COUNT_BITS = Integer.SIZE - 3; 
private static final int CAPACITY = (1 << COUNT_BITS) - 1; 

// 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; 

// Packing and unpacking ctl 
private static int runStateOf(int c)  { return c & ~CAPACITY; } 
private static int workerCountOf(int c) { return c & CAPACITY; } 
private static int ctlOf(int rs, int wc) { return rs | wc; } 

実行状態は上位ビットに格納されます。作業者数は下位ビットに格納されます。 2つを1つにまとめてintとすれば、少しメモリが節約されます。

関連する問題