我们使用 Hazelcast 2.3.1,在我们的 hazelcast.xml 配置文件中,我们使用 write behind 来创建 Hazelcast IMap:
<map name="HazelcastObjectOperations.objectMap">
<backup-count>1</backup-count>
<map-store enabled="true">
<class-name>persister.HazelcastObjectPersister</class-name>
<write-delay-seconds>10</write-delay-seconds>
</map-store>
</map>
<properties>
<property name="hazelcast.map.cleanup.delay.seconds">5</property>
</properties>
我们有两节课
HazelcastObjectOperation
它保存地图并用于将对象放入其中。HazelcastObjectPersister
扩展 MapStore 用于在 Hazelcast 调用时持久化对象storeAll()
。
public class HazelcastObjectOperation {
protected final IMap<Long, MyHzcObj> objectMap;
private final HazelcastInstance instance;
public HazelcastObjectOperation() {
this.instance = Hazelcast.getDefaultInstance();
this.objectMap = this.instance.getMap("HazelcastObjectOperations.objectMap" );
}
public void save( final MyHzcObj object ) {
long start = System.currentTimeMillis();
IdGenerator generator = Hazelcast.getIdGenerator("generator");
this.objectMap.put( generator.newId(), object );
long end = System.currentTimeMillis();
}
}
问题是当 Hazelcast 运行该映射并获取应该存储在持久类的 storeAll 方法中的对象时,该映射被锁定了几秒钟,因此这次放入该映射会持续。这个问题有什么解决办法吗?