Error when trying to create concurrent jbpm process instance
alagar_a Feb 17, 2014 11:34 AMHi,
I am creating a web application where I am encountering an issue. I have given as much as details explaining the problem.
Components:
jboss-as-7.1.1.Final for webserver
jbpm-6.0.0.Final for BPMN management
postgres-9.1 database for persistence.
UI (created in HTML/Javascript) has list of fields for getting user input in a form. On submission of this form, calls rest API service implemented in java and these rest API services are deployed in jboss. Jbpm war is deployed in jboss. Workflow BPMN diagram is created with eclipse jbpm plug-in editor and deployed in jboss. We have configured jboss to use postgresql for persistence.
Every submission of the form creates a new instance of JBPM process for BPMN workflow defined. The issue that we face is when more than one user is submitting the form at the same time, the second call fails when trying to create JPMN process instance.
Few code snippets for reference:
We are using application scoped RuntimeEnvironment.
<snip>
@Produces
@Singleton
public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf, GlobalSchedulerService globalScheduler) {
runtimeEnvironment = RuntimeEnvironmentBuilder
.getDefault()
.entityManagerFactory(emf)
.userGroupCallback(usergroupCallback)
.registerableItemsFactory(factory)
.addAsset(
ResourceFactory
.newClassPathResource("workflow.bpmn"), // workflow.bpmn is BPMN file.
ResourceType.BPMN2)
.get();
returnruntimeEnvironment;
</snip>
We have Bean managed Transaction so that we have our own transaction boundaries.
<snip>
@Startup
@javax.ejb.Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@TransactionManagement(TransactionManagementType.BEAN)
public class ourBean {
@Inject
@Singleton
private RuntimeManager singletonManager;
@Resource
private UserTransaction userTransaction;
</snip>
Code for creating new process instance in jbpm.
<snip>
userTransaction.begin();
try {
RuntimeEngine runtimeengine = singletonManager.getRuntimeEngine(EmptyContext.get());
KieSession session = runtimeengine.getKieSession();
JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(session);
ProcessInstance processinstance=session.startProcess("workflow.bpmn.id", input); //workflow.bpmn.id is id in BPMN file
jbpm_instance_id = processinstance.getId();
userTransaction.commit();
}
</snip>
When more than one user tries to submit form, we are getting the following error in jboss log. [creation of second instance of jbpm process fails]
I am getting following exception:
12:43:39,829 ERROR [stderr] (http--127.0.0.1-8080-5) java.lang.RuntimeException: Process instance 1185[workflow.bpmn.id] is disconnected.
12:43:39,830 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:90)
12:43:39,830 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:161)
12:43:39,830 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.workflow.instance.WorkflowRuntimeException.initialize(WorkflowRuntimeException.java:56)
12:43:39,830 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.workflow.instance.WorkflowRuntimeException.<init>(WorkflowRuntimeException.java:42)
12:43:39,831 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:161)
12:43:39,831 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
12:43:39,831 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:222)
12:43:39,831 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:358)
12:43:39,832 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:189)
12:43:39,832 ERROR [stderr] (http--127.0.0.1-8080-5) at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:171)
12:43:39,832 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1581)
12:43:39,832 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:366)
12:43:39,832 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:121)
12:43:39,833 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:40)
12:43:39,833 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)
12:43:39,833 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)
12:43:39,833 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.persistence.SingleSessionCommandService$TransactionInterceptor.execute(SingleSessionCommandService.java:532)
12:43:39,834 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)
12:43:39,834 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.persistence.jpa.OptimisticLockRetryInterceptor.execute(OptimisticLockRetryInterceptor.java:71)
12:43:39,834 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:374)
12:43:39,834 ERROR [stderr] (http--127.0.0.1-8080-5) at org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:232)
Following code in src/main/java/org/jbpm/process/instance/impl/ProcessInstanceImpl.java jbpm source code is throwing the error.
<snip>
public Process getProcess() {
if (this.process == null) {
if (processXml == null) {
if (kruntime == null) {
throw new RuntimeException("Process instance " + id + "[" + processId + "] is disconnected.");
}
this.process = kruntime.getKieBase().getProcess(processId);
} else {
XmlProcessDumper dumper = XmlProcessDumperFactory.newXmlProcessDumperFactory();
this.process = dumper.readProcess(processXml);
}
}
return this.process;
}
</snip>
we are not able to find the root cause of this issue. Any pointers for resolving this would be very helpful. Please let me know for any further information.