3 Replies Latest reply on May 4, 2010 4:34 AM by zecas

    jBPM DispatcherThread : J2SE and JEE behavior

    zecas

      Hi,

       

      I have a question that came when running jBPM in a J2SE environment.

       

      I'm executing the following:

       

      ProcessEngine processEngine = new Configuration().buildProcessEngine();
      

       

      From what I can tell, it will configure a process engine, and it will launch a thread, a "DispatcherThread" as it is called.

       

      That thread will be the responsible to query the jbpm database (through hibernate), to check for executions to make.

       

      That's what will keep the engine running.

       

      My question is: What about web environments?

       

      I've generated "user-webapp" through "ant create.user.webapp". It is under generated folder.

       

      If I use it as a base for a single webapp or under JEE environment, it still lauches a thread? Is there any precaution to take in this environment?

       

      What if I have several jbpm enabled applications, like J2SE and some webapps, all configured to use a central jbpm database repository for storing processes. How does each thread works? Are there any risk of complict? For example, multiple threads picking the same execution step to process.

       


      Thanks.

        • 1. Re: jBPM DispatcherThread : J2SE and JEE behavior
          sebastian.s

          Hello zecas,

           

          if I understand your post correctly it seems to me that you have misunderstood the way jBPM works. Please read the section about asynchronous continuations in the jBPM documentation. The section explains jBPM's behaviour quite well.

           

          If you invoke a jBPM operation  - as starting a process for example - the process is executed in the same java thread as the invocation originates from. The process is then executed till it reaches a state where no further activities can be executed. This is the case if the process arrives in a waiting state or in a user task for example. If you don't want this behaviour you can use the async-setting on nodes. This tells jBPM to execute the node via the JobExecutor. The JobExecutor is reponsible for continuing the execution as well as for the execution of timers.

           

          The JobExecutor itself is a thread which need to be started on jBPM initialization. Speaking of jBPM 3.2 this can be achieved via the JobExecutor servlet for example. For the actual execution of activities the JobExecutor maintains a pool of threads to perform the work. You can configure how many threads should be created.

           

          P.S.: You did not mention which version of jBPM you are using but the overall behaviour should be the same for both jBPM 3.2 and 4.x.

           

          HTH

          Sebastian

          • 2. Re: jBPM DispatcherThread : J2SE and JEE behavior
            rebody

            Hi Zecas,

              As Sebastian said,  the DispatcherThread is just used to find and execute Async Job and Timer.  It won't affect process engine.

             

              The process engine is very simple.  When you called service method, like executionService.startProcessInstanceById(), process engine will invoke related Command to execute process, the process will run through process definition until it arrival a wating Activity(StateActivity or TaskActivity) or arrival EndActivity. Whatever it turn to wait or end state, ther service will return and we could get the process instance. One request, One response.

            • 3. Re: jBPM DispatcherThread : J2SE and JEE behavior
              zecas

              Thanks for the answers, they helped me understanding why the thread launches.

               

              I'm using version 4.3

               

              My thoughts were that I call a jbpm api method, and it keeps running on the same thread until it needs further input, or the process ends, but the thread was just confusing me.

               

              I'll take a better look into jobs in the near future, as I'm learning as much as I can about jbpm.

               

               

              Thanks.