2 Replies Latest reply on Sep 1, 2014 5:27 AM by Laura delli Paoli

    per-request runtime strategy and asynchronous execution

    Laura delli Paoli Master

      Hi,

      I have jBPM6 deployment based on per-request runtime strategy (I need to have more processes in execution at the same time, see here: Run multiple processes by starting them via REST API). My processes include long running task implemented in a jar that I added to jbpm-console.war/WEB-INF/lib folder and handled with Asynchronous handlers (i.e. the workitem manager starts a thread thas does the work and then complete wirkitem).

       

      Until I used Singleton runtime strategy my process worked fine, when I changed runtime strategy to "per-request" (or to "per-process") I was not able to execute the task taht follows the long running one (no error thrown, the process blocks and does nothing). If I try to complete the workitem by using my own rest client (through junit) it completes correctly (in case of per-request only. If runtime stategy is per-process completing it gives error).

       

      Can anyone help me facing this issue?

       

      Thanks

       

      Laura

        • 1. Re: per-request runtime strategy and asynchronous execution
          Maciej Swiderski Master

          you need to use runtime manager to get RuntimeEngine and then ksession before you can complete work item. See how it is done by jbpm executor here. This code is actually valid for all three runtime strategies.

           

          HTH

          • 2. Re: per-request runtime strategy and asynchronous execution
            Laura delli Paoli Master

            thanks for your answer Maciej.

             

            Here the methods for completing workitems:

             

              private RuntimeManager getRuntimeManager() {

              trace.debug("getRuntimeManager START");

              RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);

             

             

              if (runtimeManager == null) {

              throw new IllegalStateException("There is no runtime manager for deployment " + deploymentId);

              }

             

             

              trace.debug("getRuntimeManager END");

              return runtimeManager;

              }

             

              public void completeWorkItem(long processInstanceId, long workItemId, Map<String, Object> results) {

              trace.debug("completeWorkItem START");

              RuntimeManager manager = getRuntimeManager();

              trace.debug("RuntimeManager created.");

              ProcessInstanceIdContext processContext = ProcessInstanceIdContext.get(processInstanceId);

              trace.debug("ProcessInstanceIdContext retrieved.");

              RuntimeEngine engine = manager.getRuntimeEngine(processContext);

              trace.debug("RuntimeEngine retrieved.");

              // try {

              engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results);

              // } finally {

              // manager.disposeRuntimeEngine(engine);

              // }

              trace.debug("completeWorkItem START");

              }

             

            Laura