天天看點

Java中的HashMap和ConcurrentHashMap的并發性能測試

先看看代碼吧,模拟1000個并發,每個測試1000次操作,循環測試10輪。分别測試put和get操作import java.util.collections;

運作結果

put time hashmapsync=3966ms.

put time concurrenthashmap=1892ms.

put time hashtable=3892ms.

get time hashmapsync=3812ms.

get time concurrenthashmap=1828ms.

get time hashtable=3985ms.

結論

concurrenthashmap的性能比同步的hashmap快一倍左右,同步的hashmap和hashtable的性能相當。

原帖位址:http://www.java2000.net/p12427