我刚刚同步了我的 java 代码以避免多次访问同一个列表。这是我的代码:
List<Category> list = Collections.synchronizedList(listCat);
..
pm.currentTransaction().begin();
..
synchronized (list) {
for (Category category : list) {
category.setKey(null);
tempUser.addToCategories(category);
}
}
..
pm.currentTransaction().commit();
..但我继续得到
java.util.ConcurrentModificationException: too much contention on these datastore entities. please try again.
at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:39)
at com.google.appengine.api.datastore.DatastoreApiHelper$1.convertException(DatastoreApiHelper.java:76)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:106)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:90)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:90)
at com.google.appengine.api.datastore.FutureHelper.getInternal(FutureHelper.java:72)
at com.google.appengine.api.datastore.FutureHelper.quietGet(FutureHelper.java:33)
at com.google.appengine.api.datastore.TransactionImpl.commit(TransactionImpl.java:116)
at org.datanucleus.store.appengine.jdo.DatastoreJDOTransaction.commit(DatastoreJDOTransaction.java:68)
at (the row where the transaction is committed)
..当不同的实例访问该列表时。有没有办法避免这种情况?我的意思是与此处指定的方式不同的方式: Uses for Transactions。
我使用 JDO 2.3,但我认为它不会影响这种行为