Hi,

In my app I have the following logic (pseudoCode):

List<NonSentMails> nonSentMails= getNonSentMails();//1) datastore read

List<NonSentMails> sendNow = new ArrayList<NonSentMails>(); 
for each nonSentMail in nonSentMails
   if (sendNow(nonSentMail)){
       sendNow.add(nonSentMail);
   }

for each nonSentMail in sendNow
    SentStatus sentStatus = sendMailViaRestApi();
    create maillog in datastore with sent status//2) datastore write - new 
entry
    nonSentMail.setSentStatus(sentStatus);

update(sendNow) //3) datastore write


When comitting the above I get:
java.util.ConcurrentModificationException: too much contention on these 
datastore entities. please try again.

This is a problem, as the operation is not idempotent - when I send a mail 
via a REST API the mail is sent immediately, and I want the status of my 
maillog and NonSentMail objects to reflect this.

I do not understand why this error occurs. 
There are only three operations on the datastore:
1) The initial read of non sent mails
2) The creation of new mail log entries
3) The update of the status of non sent mails

2) should never lead to ConcurrentModificationException as far as I 
understand it. 1) and 3) operates on the same entities, but 1) only reads, 
so I cannot see any problem here either.
Furthermore there is currently only one user of my app, so there should be 
no other threads accessing the data.
Note that the elements in sendNow might have the same parents, but again I 
do not believe this should be a problem?

Can you please help me understand why the above code can lead to a 
ConcurrentModificationException?

Thanks,
-Lull

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/3a6b088a-68ae-406e-bf21-e79500572fe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to