6.0.1.Final transaction completion bug
jay.guidos-bidstrading.com Feb 8, 2014 7:40 PMHi All,
I have a new problem in 6.0.1.Final that was not in 6.0.0.Final.
I have a process that starts in an EJB and the process launches a Work Item. The work item runs in its own thread, and after the work is done it updates the kieSession agenda. Depending on timing, the EJB method may complete before the work item does, as the process start() method does not wait for the process to finish.
In 6.0.0 this all worked fine, but in 6.0.1 the hibernate triggers have been changed around somewhat and I get an exception if the work item completes before the EJB method's transaction completed. The basic sequence of events is:
Thread 1: <start TX-1>
Thread 1: EJB-method: startProcess()
Thread 1: start work item, create thread 2
Thread 2: do work
Thread 2: <start TX-2>
Thread 2: update session agenda
Thread 2: <end TX-2>
Thread 2: complete work item
Thread 1: EJB-method end
Thread 1: <end TX-1>
The problem is that TX-2 causes the JPA process instance manager to disconnect all its process instances, and then throw away the kruntime and process data:
org.jbpm.process.instance.impl.ProcessInstanceImpl public void disconnect() { ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessInstanceManager().internalRemoveProcessInstance(this); process = null; kruntime = null; }
Then when the hibernate update triggers fire at the conclusion of TX-1 I get the exception trace I included below. Note that if I manage to get TX-1 completed before Thread 2 completes it's transaction then I am ok, because Thread 2 does not update the process.
I hacked a fix by not throwing away the process during the disconnect (commenting out line 5, above) which solves the problem but is fundamentally wrong. Is this a new bug or should I be doing things differently?
Jay
Caused by: java.lang.RuntimeException: Process instance 1[BidsDay.TestJobControl] is disconnected. at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:90) [jbpm-flow-6.0.1.Final.jar:6.0.1.Final] at org.jbpm.persistence.processinstance.ProcessInstanceInfo.update(ProcessInstanceInfo.java:225) [jbpm-persistence-jpa-6.0.1.Final.jar:6.0.1.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17] at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17] at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:39) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:110) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:95) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:65) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:315) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:266) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:149) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:225) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1081) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:315) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:104) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]