if (map.containsKey(key)) {
map.lock(key);
criticalSection(...);
} else {
edgeCaseCode(...);
}
Unfortunately, this leaves a gap between map.containsKey() and map.lock() for another thread to remove the key from the map, causing the lock() to hang.
On top of that, this causes Hazelcast to go onto the network twice: once for the containsKey() operation and once for the map lock.
It would be nice if lock() would throw an exception if the key is not in the map.
Kees Jan
Map.lock() should work without an existing value/mapping. Otherwise it's a bug. Can you send a test case to reproduce the issue?
@mmdogan
~Sent from mobile
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
For more options, visit https://groups.google.com/groups/opt_out.
No matter key has a value or not, key exists or not, Map.lock() should work. Locks should not depend on values.
Which version are you using? And can you write a test to reproduce the issue?
@mmdogan
~Sent from mobile
Dear Mehmet,I'd love to write a test case, but I don't know what to test for as I don't understand the expected behaviour of map.lock() for non-existent keys. :)From your responses I gather that when I lock a key on a map, I should get a lock no matter whether the value is present in the map or not. Other threads (possibly on other systems) would block on their invoke of map.lock() until the non-existent key is unlocked. Correct?
If I lock a non-existent key, what happens if the key is introduced during the lock's presence? Would subsequent calls to lock() block until unlock, or is the new item on the map considered different from the present lock?
Assuming the key is present in the map, does the locking have any effect on get() and put() operations on the same key on the same map?