public class BattleTest {
static int num=1_000_000;
@Test
public void testHashMap() throws Exception{
List<Map<Integer, Boolean>> list=new ArrayList<>(num);
for (int i = 0; i < num; i++) {
Map<Integer, Boolean> passedMap = new HashMap<>();
list.add(passedMap);
}
}
@Test
public void testConcurrentHashMap() throws Exception{
List<Map<Integer, Boolean>> list=new ArrayList<>(num);
for (int i = 0; i < num; i++) {
Map<Integer, Boolean> passedMap = new ConcurrentHashMap<>();
list.add(passedMap);
}
}
}
[size=medium]
我100万个hashMap吃了25M内存,但是用了ConcurrentHashMap吃了250M内存,
我500万个hashMap吃了250M内存,但是用了ConcurrentHashMap吃了1.1G内存,
[/size]