I was trying to understand the underlying flow of the put(K key, V value)
method of ConcurrentHashMap in OpenJDK 11, tried running it in debug mode with the below sample code how put(K key, V value)
method flow works internally, instead of understanding the flow got confused looking at high no of Hit count in IntelliJ debug Overhead tab [Refer screenshot] putVal(K key, V value, boolean onlyIfAbsent)
hit count showing for 131 hits. Just commented 2 put calls, and kept only map2.put(100, "A")
still 129 no of times Hit count it shows.
Maybe I am asking a stupid question without understanding its internals (as it is so complex to understand step-by-step even with debug mode) but curious to understand a bit of underlying flow.
Experts! can anyone put a light on my brain with a simplified explanation of the flow of how it works?
Sample Code:
import java.util.concurrent.ConcurrentHashMap;
public class Main {
static ConcurrentHashMap<Integer, String> map2 = new ConcurrentHashMap<>();
public static void main(String[] args) {
map2.put(100, "A");
map2.put(101, "B");
map2.put(102, "C");
for (Object o : map2.entrySet()) {
System.out.println(o);
}
System.out.println(map2);
}
}
Console output text for your reference:
C:\Software\jdk-11\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59187,suspend=y,server=n -javaagent:C:\Users\ravi\AppData\Local\JetBrains\IdeaIC2021.2\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "C:\POCRepo\Gateway\ConcurrentHashMapInternalFlowTest\out\production\ConcurrentHashMapInternalFlowTest;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1\lib\idea_rt.jar" com.company.Main
Connected to the target VM, address: '127.0.0.1:59187', transport: 'socket'
100=A
101=B
102=C
{100=A, 101=B, 102=C}
Disconnected from the target VM, address: '127.0.0.1:59187', transport: 'socket'
Process finished with exit code 0