Files
java-interview-lab/hashmap-vs-concurrenthashmap/output/02-sizectl-lifecycle.txt
T

17 lines
1016 B
Plaintext

ConcurrentHashMap.sizeCtl vs HashMap.threshold, single-threaded, read by reflection
===================================================================================
new ConcurrentHashMap() sizeCtl=0 table=null
after 1st put sizeCtl=12 table.length=16
after 12 puts (size=12) sizeCtl=24 table.length=32
baseCount=12 counterCells=null size()=12 mappingCount()=12 (single thread: no CounterCell was ever needed)
Sizing constructors: ask for 32 and see what each map really allocates
new ConcurrentHashMap(32) sizeCtl=64 (table not allocated yet)
after 1st put sizeCtl=48 table.length=64
new HashMap(32) threshold=32 table=null (threshold holds the initial capacity until first put)
after 1st put threshold=24 table.length=32
What sizeCtl holds while a resize is running (computed, not caught live):
resizeStamp(16)=32795 (rs << 16) + 2 = -2145714174 -> negative, so every other thread sees 'resize in progress'