[jboss-user] [JBoss jBPM] - Concurrent task acquisition (how?)

Johan.Parent do-not-reply at jboss.com
Mon Feb 5 06:04:31 EST 2007


I know the topic has been discussed frequently in this forum but I can't find the answer I'm looking for.

My question is: How to handle the concurrent access to a task assigned to an actor pool?

findPoolTaskInstance(actorId) will return all the tasks assigned to any pool the actor is a member of. But as long as you don't use setActorId() the task is not assigned. Concurrent access to the same task instance (taken from the list return by findPoolTaskInstance) will result in an exception when the data gets persisted in the DB for processes which did not set their actorId succesfully.


  |     protected boolean acquire() {
  |         // Now acquire the very first task
  |          createSession();
  | 
  |          try {
  |              jbpmContext.setActorId(actorName);
  | 
  |              // Now we search for all the tasks waiting for our actor
  |              List tasksActor = taskMgmtSession.findPooledTaskInstances(actorName);
  | 
  |              if (tasksActor.size() > 0) {
  |                  TaskInstance task = (TaskInstance) tasksActor.get(0);
  |                  task.setActorId(actorName);
  | 
  |                  jbpmContext.save(task);
  |              }
  |          }
  |          catch(Exception e) {
  |              e.printStackTrace();
  |          }
  |          finally {
  |              // Tear down the pojo persistence context.
  |              try {
  |              closeSession();
  |              }
  |              catch(Exception e) {
  |                  // If the Task is already taken you'll end up here
  |                  e.printStackTrace();
  | 
  |                  return false;
  |              }
  |          }
  | 
  |         return true;
  |     }
  | 

I'm not considering multi-threaded scenario, using synchronize would be a solution then. Catching the exception, like illustrated above, does not look like an elegant solution to me. Is there a better way? 

Best regards,

Johan

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4011267#4011267

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4011267



More information about the jboss-user mailing list