小编cha*_*nya的帖子

更好的方法在hazelcast IMap上使用clear/deleteAll

使用的示例代码:

public static void main(String[] args) {
                HazelcastInstance hz = Hazelcast.newHazelcastInstance();
                HazelcastInstance hz1 = Hazelcast.newHazelcastInstance();

                IMap<String, String> map = hz.getMap("map");

                for(int i=0; i < 1000000 ; i++) {
                                String key = "key" +Integer.toString(i);
                                String value = "value"+Integer.toString(i);
                                map.setAsync(key,value);
                }
                 System.out.println("Completed loading to Imap");
                long timeStarted = System.currentTimeMillis();
//map.clear()
//map.evictAll()
                //map.keySet().forEach(key -> map.delete(key));
map.keySet().forEach(key -> map.removeAsync(key));
                long timeComplted = System.currentTimeMillis();
                 System.out.println("time took using clear::"+(timeComplted - timeStarted));
}
Run Code Online (Sandbox Code Playgroud)

Clear():完成加载到Imap时间使用clear :: 302 CPU消耗过高(200%以上)

ecictAll():完成加载到Imap时使用clear :: 511 CPU消耗过高(200%以上)

使用每个键删除:完成加载到Imap时间使用clear :: 81578 CPU消耗很高(超过200%)

使用asyncRemove删除:已完成加载到Imap时使用clear :: …

clear hazelcast

1
推荐指数
1
解决办法
3169
查看次数

标签 统计

clear ×1

hazelcast ×1