我正在使用Hazelcast Imap接口来锁定一个分布式way.Instead中的项目,将项目放入地图中,我只调用了锁方法,这个方法看起来很有效,但我不知道如何查询哪些项当前已锁定,因为map.Is中没有项目可用,有一种方法可以查询哈泽尔广播中锁定的密钥吗?下面是示例代码: public void testMap_DistributedLock() { final Config hazelcastConfig = new ();int numberOfRecords = 100;
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(hazelcastConfig);
//monitorCluster(instance1);
IMap<Integer, Integer> myMap = instance1.getMap("myMap");
System.err.println("starting lock");
int index = 0;
while(index<numberOfRecords){
myMap.lock(index++);
}
System.err.println("After locking index is: " +index);
System.err.println("myMap.size()=" + myMap.size());
}产出如下:
starting lock
After locking index is: 100
myMap.size()=0PS:与Hazelcast 3.6一起使用java7
发布于 2016-05-04 05:55:37
没有像IMap::getLocks这样的API,但是您可以使用IMap::isLocked遍历所有已知的锁,并收集仍然处于锁定状态的密钥。如果您真的想要一些getLocks方法,请继续在github上提交一个特性请求。
https://stackoverflow.com/questions/37019350
复制相似问题