Can someone help? What am I doing wrong?

On 19 Okt., 11:04, dflorey <[email protected]> wrote:
> Hi all,
> I need help!
> I'm using concurrent tasks executed in a task queue. Let's say I want
> to spawn 100 concurrent tasks and do something once they are all done.
> I thought this is simple by just storing the total number of spawned
> tasks into the datastore and let each task decrease the number by 1.
> The value should be 0 when all tasks are done.
> This is my code snippet to decrease the value:
>
> Transaction tx = datastore.beginTransaction();
> try {
>         Entity entity = datastore.get(tx, KeyFactory.createKey(kind, key));
>         Long number = (Long) entity.getProperty(column);
>         if (number == null || number == 0) {
>                 tx.commit();
>                 return 0;
>         }
>         number -= 1;
>         entity.setProperty(column, number);
>         datastore.put(tx, entity);
>         tx.commit();
>         return number;} catch (Exception e) {
>
>         throw new DBException("Failed to decrease counter, force retry!", 
> e);} finally {
>
>         if (tx.isActive()) {
>                 tx.rollback();
>         }
>
> }
>
> Something must be wrong with my code as from time to time two
> concurrent tasks return the same number after decreasing the value.
> Can someone please give me an advice?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to