2 Replies Latest reply on Jan 27, 2006 4:58 AM by claudio.masini

    How to Manage Concurrency assigning a task

    claudio.masini

      Hi, I have a question regarding task assignment.
      If I set a pool of actors to a task means that several people can have the same task in their tasklist.
      When a user decide to work on a task the API suggests you to immediately assign the task to the user removing the task from the other actors task list.

      This work fine but in a web application we show the list of tasks in a page and is quite easy that 2 users click on the same task so we can control that tha task is un-assigned before assigning it.
      This will solve a lot of cases but because it's not an atomic process it could fail the same.

      Does anybody knows a possible solution to avoid this?
      Consider that we are working on a cluster and this means we can't use

      "synchronized"
      blocks.

      Many thanks for any idea

      Claudio

        • 1. Re: How to Manage Concurrency assigning a task
          ralfoeldi

          Hi Claudio,

          I can't help you on the Task part but as soon as you have concurrency you would have to lock on processInstance anyway before executing anything.

          The only reliable place to do that is in a database. Jbpm gives you GraphSession.lockProcessInstance() or use Hibernate directly. This will i.e. place a 'select for update' lock on the rows in your db (depends on Hibernate settings).

          You will probably only want to do this for the time it takes to set your assignment correctly.

          Does this help?

          Greetings

          • 2. Re: How to Manage Concurrency assigning a task
            claudio.masini

            I will try to use org.hibernate.Session.lock(task, LockMode.UPGRADE) to see if this will solve the problem.

            Locking the process instance give me the idea that it locks only that object.
            I will let you know if it work.

            Many thanks for the idea (I'm studying hibernate at the same time... so I'm pretty novice with it)

            Thanks a lot

            Claudio