Hello, i've got some problems with transactions when there is the exception java.util.ConcurrentModificationException.
When i've got this exception, i tried a retry but when i'm looking in my datastore viewer my incrementation didn't work.
For example when i'm testing with 30 simultaneous users, my data was incremented 28 times. 2 incrementations are missing and i've got 2 java.util.ConcurrentModificationException.
Somebody knows why? How can i solve this problem.
int answerNb = Integer.parseInt(req.getParameter("answer"));
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery("select from " + Question.class.getName());
query.setFilter("date == dateParam");
query.declareParameters("String dateParam");
List<Question> questions = (List<Question>) query.execute(req.getParameter("date"));
if(!questions.isEmpty()) {
int retryCount = 0;
while (retryCount++ < 30) {
pm.currentTransaction().begin();
questions.get(0).getAnswers().get(answerNb).increment();
try {
pm.currentTransaction().commit();
break;
}
catch (Exception x) {
//retry
}
}
my method increment in a java class
public void increment() {
counter ++;
}