import java.util.concurrent.atomic.AtomicInteger;
public class ThreadLocalTest {
private static AtomicInteger nextHashCode = new AtomicInteger();
//https://www.cnblogs.com/ilellen/p/4135266.html
//https://www.jianshu.com/p/640f2c0ac4b0
//https://www.jianshu.com/p/cdb2ea3792b5
private static final int HASH_INCREMENT = 0x61c88647;
private static final int INITIAL_CAPACITY = 16;
public static void main(String[] args){
for(int i = 0; i < INITIAL_CAPACITY; i++){
System.out.println(getIndex());
}
}
private static int nextHashCode() {
int hashCode = nextHashCode.getAndAdd(HASH_INCREMENT);
System.out.print(String.format("hashCode: 0x%x \t index: " , hashCode));
return hashCode;
}
private static int getIndex(){
return nextHashCode() & (INITIAL_CAPACITY - 1);
}
}