how to retry/recover from a java.sql.SQLexception: Concurrent Modification
Using JDO on GAE, I'm using a simple database transaction code block like below.
What is a good way to retry/recover from a thrown java.sql.SQLException: Concurre开发者_StackOverflow中文版nt Modification?
private final Provider pmp; ...
PersistenceManager pm = pmp.get(); try { pm.currentTransaction().begin();
MyObject myObject= pm.getObjectById(MyObject.class, id);
pm.currentTransaction().commit();
} finally {
if (pm.currentTransaction().isActive()) { log.severe( this.getClass().getName() + " caught DATABASE exception."); pm.currentTransaction().rollback(); } }
Where is that exception actually thrown? Are you sure about the semantics of commit() and isActive()? commit() could automatically create a new transaction leaving the transaction always active.
My other guess would be that this is a singleton bean accessed concurrently and they all end up in the same transaction with other queries concurrently modifying your requested object.
精彩评论