Handle InvalidItemStateException in jackrabbit
-
06-07-2019 - |
Question
We are now experiencing a number of InvalidItemStateException in our web application caused by 2 or more users updating the same content. As far as I understood it is in design of JackRabbit to throw javax.jcr.InvalidItemStateException
in such situation and that's ok, but I wanted to ask about the common way to handle that. We are fairly ok that the last processed change wins the update. So far we have come up with the following code:
repeat = false;
do {
try {
// Do node update/remove
} catch (InvalidItemStateException e) {
repeat = true;
}
} while (repeat);
Is this a common pattern how to handle that? Or is it a better way to avoid such situations?
Solution
JCR (and Jackrabbit) has a node locking mechanism that may be better suited for this... sorry, though I have not used it yet to be sure that it would solve your problem.
Good luck.
OTHER TIPS
In order to avoid InvalidItemStateException every thread/user should have it's own Session object.