Hi,
I am reading the official GAE documentation on transactions and I
can't understand when a ConcurrentModificationException is thrown.
Look at one of the examples which I am copy-pasting here:
int retries = 3;
while (true) {
Transaction txn = datastore.beginTransaction();
try {
Key boardKey = KeyFactory.createKey("MessageBoard",
boardName);
Entity messageBoard = datastore.get(boardKey);
long count = (Long) messageBoard.getProperty("count");
++count;
messageBoard.setProperty("count", count);
datastore.put(messageBoard);
txn.commit();
break;
} catch (ConcurrentModificationException e) {
if (retries == 0) {
throw e;
}
// Allow retry to occur
--retries;
} finally {
if (txn.isActive()) {
txn.rollback();
}
}
}
Now, all the writes to the datastore (in this example) are wrapped
under a transaction. So why would a ConcurrentModificationException be
thrown?
Does it happen when some other code which is not wrapped in a
transaction updates the same entity that is being modified by the
above code? If I ensure that all code that updates an Entity is always
wrapped in a transaction, is it guaranteed that I won't get a
ConcurrentModificationException?
thanks,
Harshad
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.