13 Replies Latest reply on Jun 6, 2007 9:54 AM by estaub

    please help: concurrent paths execution

    ax666

      Hi all, I'm really stuck with this problem now, and after reading for hours it didn't get any better. I'm using jbpm 3.2, here's a simple example of what I want do do:

      <process-definition>
       <start-state name="start1">
       <transition name="to-fork" to="fork1"/>
       </start-state>
      
       <fork name="fork1" async="true">
       <transition name="to-proc1" to="proc1"/>
       <transition name="to-proc2" to="proc2"/>
       </fork>
      
       <process-state name="proc1" async="true">
       <sub-process name="doThatThing"/>
       <variable name="p1.doWhat" access="read" mapped-name="doWhat"/>
       <transition name="1to-join" to="join1"/>
       </process-state>
      
       <process-state name="proc2" async="true">
       <sub-process name="doThatThing"/>
       <variable name="p2.doWhat" access="read" mapped-name="doWhat"/>
       <transition name="2to-join" to="join1"/>
       </process-state>
      
       <join name="join1" async="true">
       <transition name="to-end" to="end"/>
       </join>
      
       <end-state name="end">
       </end-state>
      </process-definition>
      


      all of this is running in a tomcat with a JobExecutor having more than 1 thread. I'm having several issues with this scenario which due to lack of deep experience with jbpm/hibernate I can't solve.
      First, JobExecutor tries to work on the same job within different threads.
      Second, the join node runs into a hibernate sync problem because both tokens work with the parent token.
      Note: the join node problem occurs only if the two sub-processes finish at the same time.

      I think I'm missing something here in general. Any help is appreciated to point me in the right direction. All I want is to run the two (complex) sub-processes simultaneously. Again, reading all the old threads did not really help.
      Thanks, Alex

        • 1. Re: please help: concurrent paths execution

          Alex,

          Do you understand how your fix of yesterday (see http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049235#4049235) is not working?

          I see two possibilities, but I don't know the code that well, so both could be wrong... you might want to instrument for these...

          1.) Imagine that acquireJobs() has just finished executing on one thread, and the engine is now working on those jobs. Another job for the same process instance is queued, and another thread picks it up. In my admittedly brief reading, I don't see what synchronizes access to the process instance.

          2.) In your case, I believe the jobs will be on the subprocesses, but both threads end up modifying the parent process. Is there anything synchronizing access to the parent process? I don't see it. The key point appears to be ProcessInstance.end().

          You should probably update the JIRA.
          Also, in the JIRA you might more pointedly refer to the forum discussion(s).

          -Ed Staub

          • 2. Re: please help: concurrent paths execution
            ax666

            Ed, my yesterday's fix (or hack) does work so far, concerning job acquirement. I think all the hibernate sync doesnt work with multiple threads in one process instance. I wish someone from jboss would say a word, but I guess they're either tired of repeating "it's a business process tool, not a thread scheduler" or it's just the usual no time/no desire/whatever....
            threads and their hibernate sessions are not sync'd between each other, but I dont know if thats just incorrect use, wrong configuration or bugs. I need this thing get to work soon without spending days on it, otherwise I will need to look for something different that works out of the box (which probably doenst exist)...
            A.

            • 3. Re: please help: concurrent paths execution

              Alex,

              In ProcessInstance.end(), consider session-locking the parent process token while the signal() is performed on it. Sorry, I don't know where to get the Session object from, what locking mode to use, etc. - I'm not skilled with Hibernate yet. Look at Join.execute() as a model.

              I appreciate where you're coming from with some of your other comments...

              -Ed Staub

              • 4. Re: please help: concurrent paths execution
                ax666

                I could synchronize in JobExecutorThread on the parent token, but that hack seems even dirtier than the other. I'll give it a try though ;)

                What did everyone else do in case of concurrent threads in a process instance? the discussions I found in the forum never came to a conclusion...

                I'm leaving the jira issue as is for now...

                • 5. Re: please help: concurrent paths execution
                  kukeltje

                  I think most people do not have STP kind of processes where multiple threads need to have access to the same processinstance (and yes, it is not thread a thread scheduler ;-) and yes they have desire, no time, well limited at the moment, but (shameless plug) you could order commercial support ;-).

                  I'll signal the developers make a statement/comment on this.

                  • 6. Re: please help: concurrent paths execution
                    tom.baeyens

                    if you don't want jobs from the same process instance to be executed concurrently, you should try async="exclusive"

                    don't remember if i also added this for timers. the idea is that exclusive jobs will all be acquired by 1 thread in one tx. and then they are executed by that single thread sequentially.

                    • 7. Re: please help: concurrent paths execution
                      kukeltje

                      Look.... guys.... isn't this great..... at 11:01 according to the post (it was 17:01) here. I posted, then send a mail to the developers et voila at 17:13 local time they responded... compliments to the JBoss guys...

                      • 8. Re: please help: concurrent paths execution
                        ax666

                        good to know, but actually I want them to be executed concurrently. I have (long running) sub processes that have to be executed simultaneously, two for now, but more later. it's just the synchronization in the parent process that is making trouble.... concerning "exclusive" : I noticed that some attributes/values are in the code, but not in the documentation and not in the schema.... just not stable enough?

                        • 9. Re: please help: concurrent paths execution
                          ax666

                           

                          "kukeltje" wrote:
                          Look.... guys.... isn't this great..... at 11:01 according to the post (it was 17:01) here. I posted, then send a mail to the developers et voila at 17:13 local time they responded... compliments to the JBoss guys...


                          everyone is fresh and full of energy at this morning time ;)

                          • 10. Re: please help: concurrent paths execution
                            kukeltje

                            According to http://jira.jboss.com/jira/browse/JBPM-713 it is implemented for timers to. Where should this go in the docs.... I cannot find it in there. Then I can create a jira issue for adding this to the docs.

                            Does 'exclusive' mean that the other jobs for other proces instances will be executed in parallel to this one?

                            • 11. Re: please help: concurrent paths execution
                              kukeltje

                              Docs and schema are behind..... as always... :-)

                              btw, surprise Ax666 this developer is in europe and so it is the END of the workingday.....5pm!!

                              • 12. Re: please help: concurrent paths execution
                                ax666

                                developers have their special day schedule, no developer would have a clear mind at 7 am ... :)

                                my bad hack is working, I'm synchronizing on the parent token before I let the JobExecutor thread execute the job. I will play with that a little more, but I guess this is what we will be using...

                                Still, I think this issue should be solved in a clean way...

                                Alex

                                • 13. Re: please help: concurrent paths execution

                                  Ronald,

                                  I haven't written a test yet, but as I read the code this is not implemented for timers. See CreateTimerAction.java.

                                  Also, relative to both this and Alex's other problem of today (http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4051686#4051686)

                                  I really need to write a test for this. To repeat: as I see it, if a thread is executing an exclusive job for a token, and another event comes in on the same token that spawns a job, there's nothing preventing another thread from trying to run with it, theoretically resulting in what Alex is seeing in both cases.

                                  -Ed Staub