0
我正在使用Hazelcast Imap接口以分佈式方式鎖定項目。取而代之的是將項目放入地圖中,我只是調用鎖定方法,但似乎正在工作,但我不知道如何查詢當前哪些項目被鎖定,因爲項目在地圖中不可用。是否有方法可以查詢有關鎖定鍵的榛木? 下面是示例代碼: public void testMap_DistributedLock(){ final Config hazelcastConfig = new Config(); int numberOfRecords = 100;如何確定哪些鍵被鎖定與Hazelcast Imap
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()=0
PS:使用java7與Hazelcast 3.6