java查看concurrenthashmap占多大内存
1个回答
2017-08-18
展开全部
Java代码 收藏代码
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);
}
}
}
我100万个hashMap吃了25M内存,但是用了ConcurrentHashMap吃了250M内存,
我500万个hashMap吃了250M内存,但是用了ConcurrentHashMap吃了1.1G内存,
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);
}
}
}
我100万个hashMap吃了25M内存,但是用了ConcurrentHashMap吃了250M内存,
我500万个hashMap吃了250M内存,但是用了ConcurrentHashMap吃了1.1G内存,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |