可能重複:
What’s the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?當使用的ConcurrentHashMap
我讀的HashMap,Collenctions.synchonizedMap和ConcurrentHashMap的差異。我的理解是Collections.synchronizedMap對整個集合應用了鎖,因此性能開銷。但是ConcurrentHashMap不使用同步。它使用段來實現結果,因此它提供了與HashMap相似的性能。
請建議,如果我的理解是正確的。此外,如果是這種情況,即使可能沒有多個線程訪問它,我是否可以使用ConcurrentHashMap?
我也經歷了這個問題。它主要討論涉及多個線程並且需要併發的情況。但是,我想了解是否可以使用ConcurrentHashMap,即使我只能使用HashMap。 – mehta
你可以....但你爲什麼?你沒有理由增加開銷; 「相似」!=「相同」。 –
在這種情況下,你可以看看http://stackoverflow.com/questions/1378310/performance-concurrenthashmap-vs-hashmap – Swapnil