I have a ConcurrentMap that gets instantiated outside of my runnables, but shared and updated within / accross the runnables. My runnables need to be concurrent, but my conc
You should avoid synchronizing when using a ConcurrentMap. It provides other methods for handling these types of operations. For this case the putIfAbsent method should be preferred over a contains and then a put.
public void runAnalysis(int index) {
if (concurrentMap.putIfAbsent(index, "thread " + thread) == null) {
System.out.println("put " + index + " thread " + thread);
} else {
System.out.println("contains integer " + index);
}
}