6 Replies Latest reply on Nov 25, 2014 3:27 AM by Maciej Swiderski

    how to launch any process in parallel

    Domenico Schiavone Newbie

      hi to all,

      I need to know how to do to launch any process in parallel, for example I have a simple app that launch the process with 3 script task:

       

      public static void main(String[] args) {

              KieServices ks = KieServices.Factory.get();

              KieContainer kContainer = ks.getKieClasspathContainer();

              KieBase kbase = kContainer.getKieBase("kbase");

       

              RuntimeManager manager = createRuntimeManager(kbase);

              RuntimeEngine engine = manager.getRuntimeEngine(null);

              KieSession ksession = engine.getKieSession();

             

            

              ksession.startProcess("com.sample.bpmn.hello");

       

      now I must launch start process 10 times but in parallel and not in sequence.

       

      Somebody can help me???

        • 1. Re: how to launch any process in parallel
          Maciej Swiderski Master

          use different threads to lunch the process instances. Just few thoughts on what ti keep in mind:

          • create runtime manager before you use threads to start process instances
          • don't use singleton runtime manager strategy as singleton will synchronize all executions which essentially means you will have then done in sequence
          • make sure to always get runtime engine and dispose runtime engine in each thread with use of proper context

          That will give you parallel execution of your process instances

           

          HTH

          • 2. Re: how to launch any process in parallel
            Domenico Schiavone Newbie

            thanks for the response like even XD,

            what kind of strategy I should use to have a simple launch of any process in parallel? are there any examples about it?

            • 3. Re: how to launch any process in parallel
              Maciej Swiderski Master

              most likely best would be to use per process instance

               

              HTH

              • 4. Re: how to launch any process in parallel
                Domenico Schiavone Newbie

                I tried to change this code with singleton:

                private static RuntimeManager createRuntimeManager(KieBase kbase) {

                        JBPMHelper.startH2Server();

                        JBPMHelper.setupDataSource();

                        EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

                        RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get()

                            .newDefaultBuilder().entityManagerFactory(emf)

                            .knowledgeBase(kbase);

                        return RuntimeManagerFactory.Factory.get()

                            .newSingletonRuntimeManager(builder.get(), "com.sample:example:1.0");

                    }

                 

                I have changed .newSigletonRuntimeManager with newPerProcess....... but after this the console give me a error in getRuntimeEngine:

                this.ks = KieServices.Factory.get();

                        this.kContainer = ks.getKieClasspathContainer();

                        this.kbase = kContainer.getKieBase("kbase");

                 

                        this.manager = createRuntimeManager(kbase);

                       this.engine = manager.getRuntimeEngine(null);

                        this.ksession = engine.getKieSession();

                        this.taskService = engine.getTaskService();

                        this.logService = engine.getAuditLogService();

                 

                The log of error is:

                SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".

                SLF4J: Defaulting to no-operation MDCAdapter implementation.

                SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.

                Exception in thread "main" java.lang.NullPointerException

                    at org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager.getRuntimeEngine(PerProcessInstanceRuntimeManager.java:94)

                    at com.sample.ProcessMain.<init>(ProcessMain.java:46)

                    at com.sample.Manager.main(Manager.java:8)

                • 5. Re: how to launch any process in parallel
                  Domenico Schiavone Newbie

                  is there a different way to use a PerProcess strategy?? any example??

                  • 6. Re: how to launch any process in parallel
                    Maciej Swiderski Master

                    you cannot use null as context when retrieving RuntimeEngine - as name suggest you need to use ProcessInstanceIdContext instead. It has two options:

                    • empty - ProcessInstanceId.get() - when you start new process instance - meaning there is no context set yet - no process instance
                    • with process instance id - ProcessInstanceId.get(processInstanceId) - when there is given process instance already active that you want to work with.

                    See examples here.

                     

                    HTH