8 Replies Latest reply on Mar 16, 2015 3:26 PM by Suresh M

    How to load multiple process(BPMN) at runtime

    Suresh M Newbie

      Hello!

       

      I have configured RuntimeEnvironment and RuntimeManager in my spring config file as follows. Also am loading BPMN resource from local drive to assets. I am using JBPM 6.2.0.Beta1 version

       

      <bean id="loadMultipleBpmnFiles" class="xxx.xxx.xxx.LoadMultipleBpmnFiles">

              <property name="bpmnFilePath" value="${bpmn.file.path}"/>

          </bean>

       

      <bean id="runtimeEnvironment"

              class="org.kie.spring.factorybeans.RuntimeEnvironmentFactoryBean">

              <property name="type" value="DEFAULT" />

              <property name="entityManagerFactory" ref="entityManagerFactory" />

              <property name="transactionManager" ref="jbpmTxManager" />

              <property name="assets" value="#{loadMultipleBpmnFiles.bpmnfiles}"/>

              <property name="taskService" ref="taskService" />

          </bean>

       

          <bean id="runtimeManager" class="org.kie.spring.factorybeans.RuntimeManagerFactoryBean"

              destroy-method="close">

              <property name="identifier" value="spring-rm" />

              <property name="runtimeEnvironment" ref="runtimeEnvironment" />

          </bean>

      Java class: LoadMultipleBpmnFiles

           for (File file : bpmnFiles) {

                      if (file.isFile()) {

                          bpmnfiles.put(ResourceFactory.newFileResource(file.getAbsolutePath()), ResourceType.BPMN2);

                          filecount++;

                      }

                  }

       

      ProcessEngine as follows:

      @Autowired

          private RuntimeManager runtimeManager;

       

           public long startProcess(String processId, Map<String,Object> parameters)

           {

           RuntimeEngine engine = runtimeManager.getRuntimeEngine(EmptyContext.get());

              KieSession ksession = engine.getKieSession();

              taskService = engine.getTaskService();

              processInstance = ksession.startProcess(processId,parameters);

      }

      Before start server, I have one BPMN file at bpmnfilepath directory and deployed war,it is working fine without any issue.

       

      Without Restart server: Now i have added one more BPMN file to bpmnfailePath directory and without restart server, the new process do not load at runtimeenvironment and runtimemanager. Because bean has initialized  only once. Please help me how to dynamically load new process to RuntimeManager without restarting server.

      Thanks Suresh M

        • 1. Re: How to load multiple process(BPMN) at runtime
          Maciej Swiderski Master

          for that to happen you would need to close and create RuntimeManager once again. There is no auto discovery of processes on file system feature so you need to handle it in your application code.

           

          HTH

          • 2. Re: How to load multiple process(BPMN) at runtime
            Suresh M Newbie

            Thanks Maciej,

             

            If I close RuntimeManager, at the same time some one continue the complete the task which is already created. In this case RuntimeManager instance is not available right?

            • 3. Re: How to load multiple process(BPMN) at runtime
              Maciej Swiderski Master

              correct, in such a case you would need to synchronize access to runtime manager at that time to avoid any risks of accessing temporarily closed runtime manager.

               

              HTH

              • 4. Re: How to load multiple process(BPMN) at runtime
                Suresh M Newbie

                Hi Maciej,

                As per your comments, I have made it synchronized block, closing and recreate RuntimeManager. But when i try to complete task which is already inprogress status, not able to complete and getting Error "RuntimeManager spring-rm is already closed"

                I did the following steps.

                1. Initiate RuntimeManager by spring

                @Autowired

                private RuntimeManager runtimeManager;

                2. Started JBoss AS server

                3. while deploying reading *.bpmn file from local directory (check above code). Having two bpmn files.

                4. Started one process -- ksession.startProcess(processId,parameters). Process instance id "1" was created and task id "1" was created with "Reserved" status.

                5. Now another user has copied one new bpmn file into local directory.(Total count is 3)

                6. temporarily closed runtime manager. For loading new assets into runtime manager

                                        runtimeManager.disposeRuntimeEngine(engine);

                7. Recreated Runtime Manager

                runtimeManager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(builder.get(), identifier); //Same spring-rm identifier

                8. I was trying to complete the task Id "1" from recreated runtime manger.

                     public TaskService getTaskService(long processInstanceId) {

                       return runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)).getTaskService();

                    }

                Call complete task method

                public void completeTask(long taskId, String user, long processInstanceId) {

                        getTaskService(processInstanceId).complete(taskId, user, null);

                    }

                getting error "Runtime manager spring-rm is already closed"

                 

                Please let me how can I resolve this issue.

                 

                12:17:19,070 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) Error Message :::Runtime manager spring-rm is already closed

                12:17:19,071 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) java.lang.IllegalStateException: Runtime manager spring-rm is already closed

                12:17:19,072 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager.validate(PerProcessInstanceRuntimeManager.java:148)

                12:17:19,073 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:90)

                12:17:19,075 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:266)

                12:17:19,076 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:262)

                12:17:19,077 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:1868)

                12:17:19,079 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:128)

                12:17:19,081 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:74)

                 

                12:17:19,082 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:35)

                 

                12:17:19,083 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)

                 

                12:17:19,085 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)

                 

                12:17:19,086 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.persistence.SingleSessionCommandService$TransactionInterceptor.execute(SingleSessionCommandService.java:509)

                 

                12:17:19,088 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)

                 

                12:17:19,089 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.persistence.jpa.OptimisticLockRetryInterceptor.execute(OptimisticLockRetryInterceptor.java:73)

                 

                12:17:19,090 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)

                 

                12:17:19,091 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.persistence.jta.TransactionLockInterceptor.execute(TransactionLockInterceptor.java:60)

                 

                12:17:19,092 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:353)

                 

                12:17:19,093 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession$1.completeWorkItem(CommandBasedStatefulKnowledgeSession.java:145)

                 

                12:17:19,095 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.wih.ExternalTaskEventListener.processTaskState(ExternalTaskEventListener.java:77)

                 

                12:17:19,096 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.wih.ExternalTaskEventListener.afterTaskCompletedEvent(ExternalTaskEventListener.java:119)

                 

                12:17:19,097 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.events.TaskEventSupport.fireAfterTaskCompleted(TaskEventSupport.java:198)

                 

                12:17:19,097 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.internals.lifecycle.MVELLifeCycleManager.taskOperation(MVELLifeCycleManager.java:355)

                 

                12:17:19,098 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.identity.UserGroupLifeCycleManagerDecorator.taskOperation(UserGroupLifeCycleManagerDecorator.java:48)

                 

                12:17:19,099 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.impl.TaskInstanceServiceImpl.complete(TaskInstanceServiceImpl.java:139)

                 

                12:17:19,100 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.commands.CompleteTaskCommand.execute(CompleteTaskCommand.java:70)

                 

                12:17:19,101 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.commands.CompleteTaskCommand.execute(CompleteTaskCommand.java:37)

                 

                12:17:19,102 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.commands.CompositeCommand.execute(CompositeCommand.java:38)

                 

                12:17:19,106 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.commands.TaskCommandExecutorImpl$SelfExecutionCommandService.execute(TaskCommandExecutorImpl.java:65)

                 

                12:17:19,108 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)

                 

                12:17:19,109 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:54)

                 

                12:17:19,110 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40)

                 

                12:17:19,111 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jbpm.services.task.impl.command.CommandBasedTaskService.complete(CommandBasedTaskService.java:144)

                 

                12:17:19,112 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at com.boeing.ecfd.cg.bpm.engine.ProcessEngine.completeTask(ProcessEngine.java:332)

                 

                12:17:19,112 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at com.boeing.ecfd.cg.bpm.service.DoCfdServiceImpl.startProcess(DoCfdServiceImpl.java:545)

                 

                12:17:19,114 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at com.boeing.ecfd.cg.bpm.controller.DoCfdBpmController.startProcess(DoCfdBpmController.java:87)

                 

                12:17:19,115 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                 

                12:17:19,115 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                 

                12:17:19,116 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                 

                12:17:19,118 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at java.lang.reflect.Method.invoke(Method.java:597)

                 

                12:17:19,119 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)

                 

                12:17:19,121 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

                 

                12:17:19,122 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

                 

                12:17:19,123 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)

                 

                12:17:19,125 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)

                 

                12:17:19,126 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

                 

                12:17:19,128 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

                 

                12:17:19,128 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

                 

                12:17:19,129 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

                 

                12:17:19,130 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)

                 

                12:17:19,131 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

                 

                12:17:19,132 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

                 

                12:17:19,132 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

                 

                12:17:19,133 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

                 

                12:17:19,135 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

                 

                12:17:19,135 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)

                 

                12:17:19,136 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)

                 

                12:17:19,138 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

                 

                12:17:19,139 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

                 

                12:17:19,140 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

                 

                12:17:19,142 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)

                 

                12:17:19,143 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

                 

                12:17:19,145 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

                 

                12:17:19,146 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                 

                12:17:19,148 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                 

                12:17:19,149 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

                 

                12:17:19,150 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

                 

                12:17:19,152 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

                 

                12:17:19,153 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

                 

                12:17:19,154 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at java.lang.Thread.run(Thread.java:619)

                • 5. Re: How to load multiple process(BPMN) at runtime
                  Maciej Swiderski Master

                  most likely spring auto wire is getting in the way and still providing you with old instance of runtime manager. If you do recreate runtime manager then I'd recommend remove any spring management code that can cache it in anyway.

                   

                  HTH

                  • 6. Re: How to load multiple process(BPMN) at runtime
                    Suresh M Newbie

                    Thanks Maciej for your updates!

                     

                    I followed you and removed spring management code in application and create/closed/recreate runtimemanager thru manually. But still am getting same error.

                    1. Started new process and got instance id as "1" and task id "1"


                    private RuntimeManager runtimeManager;


                    public RuntimeManager getRuntimeManager() {

                           

                                System.out.println("Runtime manager is null");

                                RuntimeEnvironmentBuilder builder = null;

                                RuntimeEnvironmentBuilderFactory factory  = RuntimeEnvironmentBuilder.Factory.get();

                                builder = factory.newDefaultBuilder();

                                ..........

                                ............

                                runtimeManager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(builder.get(), identifier);

                         

                            return runtimeManager;

                        }

                     

                         public long startProcess(String processId, Map<String,Object> parameters) {

                            RuntimeEngine engine = getRuntimeManager().getRuntimeEngine(ProcessInstanceIdContext.get());

                            ProcessInstance processInstance = ksession.startProcess(processId,parameters);

                            return processInstance.getId();

                        }

                     

                    // New RuntimeManager has been created --- org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager@117fd27

                    //Closed existing Runtime Manager and Recreate it

                            try{

                                synchronized(runtimeManager){

                                   if(null != runtimeManager){

                                        runtimeManager.close();

                                    }

                                   runtimeManager = getRuntimeManager(); // Calling create Runtime manager

                                 }

                            }catch(Exception ex){

                                 ex.printStackTrace();

                            }

                    Created new Runtime Manager ---- org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager@12f5fb6    

                    When i try to completed the task id "1" with instance id "1"

                    public TaskService getTaskService(long processInstanceId) {

                            return getRuntimeManager().getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)).getTaskService();

                        }

                    getTaskService(processInstanceId).start(taskId, user); //  able to start the task with new runtime manager object (org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager@12f5fb6)


                    getTaskService(processInstanceId).complete(taskId, user, null); //not able to complete but when i put debug point, it showing latest

                    runtimemanager(RuntimeManager@12f5fb6). While reaching the JPAProcessInstanceManager class is returning closed runtimemanager object(RuntimeManager@117fd27). It is really surprise me. Could you please let me know how can i get latest runtimemanager object and then complete the existing task id.

                     

                    Because of this am getting "Runtime manager spring-rm is already closed". Also plz explain to me, why the InternalRuntimeManager is holding old RM, how to register the new RM.

                     

                    org.jbpm.persistence.processinstance.JPAProcessInstanceManager // When I

                    public ProcessInstance  [More ...] getProcessInstance(long id) {

                             return getProcessInstance(id, false);

                    }

                    public ProcessInstance  [More ...] getProcessInstance(long id, boolean readOnly) {

                             InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get("RuntimeManager");

                             if (manager != null) {

                                 manager.validate((KieSession) kruntime, ProcessInstanceIdContext.get(id));

                             }

                             .....................

                    org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager

                    public void  [More ...] validate(KieSession ksession, Context<?> context) throws IllegalStateException {

                        if (isClosed()) {

                            throw new IllegalStateException("Runtime manager " + identifier + " is already closed");

                    }

                    • 7. Re: How to load multiple process(BPMN) at runtime
                      Maciej Swiderski Master

                      looks like you getTaskService is using old ksession as RuntimeManager is put into ksession environment and then used by JPAProcessInstanceManager. So make sure that you always take new RuntimeEngine whenever interacting with task service and ksession as that will always create new instance of ksession. You cannot reuse ksession especially since you're changing runtime manager...

                       

                      HTH

                      • 8. Re: How to load multiple process(BPMN) at runtime
                        Suresh M Newbie

                        Thanks for your reply Maciej!

                        Still am getting same issue RuntimeMnager is already closed.

                        1. First time create RuntimeManager

                        private RuntimeManager runtimeManager;

                        TaskService taskService;

                            KieSession ksession;

                        public void createRuntimeManager(){

                        ....................

                             {

                                   runtimeManager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(builder.get(), identifier);

                                     RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());

                                     ksession = engine.getKieSession();

                                     taskService = engine.getTaskService();

                              }

                        }

                        2. start process, create process instance id

                             public long startProcess(String processId, Map<String,Object> parameters) {

                               ProcessInstance processInstance = ksession.startProcess(processId,parameters);

                                return processInstance.getId();

                            }

                             

                        3. Closed/recreate Runtimemanager for added new process

                             try{

                                    synchronized(runtimeManager){

                                      if(null != runtimeManager){

                                            runtimeManager.close();

                                        }

                                       

                                       runtimeManager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(builder.get(), identifier);

                                          RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());

                                          ksession = engine.getKieSession();

                                          taskService = engine.getTaskService();

                         

                                     }

                                }catch(Exception ex){ ..}

                         

                        4. Trying to complete the task which is already created bfore closing runtimemanager

                        public void completeTask(long taskId, String user, long processInstanceId) {

                                RuntimeEngine runtimeEngine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());

                                taskService = runtimeEngine.getTaskService();

                                taskService.complete(taskId, user, null);

                            }

                         

                        Still am getting "Runtime manager spring-rm is already closed". Could you please let me know how can i resolve this issue. I have tried may ways but am not able to resolve this issue.

                        Thanks in Advance!