Just do all those things within a transaction. Locks should be acquired automatically.
If you want to specifically get a write lock on the parent node as well, look at:
and look for the LockParentForChildInsertRemove attribute.
Thanks for your reply :-)
Should I use a specific Node Locking Scheme to ensure that behaviour? At the moment, I use Optimistic scheme (and, consequently, no Isolation Level).
Here's what's happenning at the moment:
- put some data in the cache.
- modify its definition -> remove() is called
- update its value -> put() is called with the new value
The problem is that if I call get() on that node between the remove() and the put(), I still obtain the old value, but shouldn't I obtain null??
LockParentForChildInsertRemove works with both optimistic and pessimistic locking.
You won't receive a null in your above scenario since the write (in this case, the remove() call) will not be visible to other threads until the transaction commits.
Thanks for the info on LockParentForChildInsertRemove, I'm going to try that.