umberto maguolo [
https://community.jboss.org/people/umb71] created the discussion
"Re: timer job issues when disposing session in embedded j2ee process"
To view the discussion, visit:
https://community.jboss.org/message/824964#824964
--------------------------------------------------------------
Hi,
ok, i've found a solution. In my EJB project, in the method exposed, i create a
knowledge session per call, and a single process instance:
1. create the process instance:
logger.debug(">>> create a process instance");
ProcessInstance procInstance =
ksession.createProcessInstance("test.TestComplete", params);
2. register transaction manager synchronization using Maciej's original
CMTDisposeCommand (in the afterCompletion method i dispose the ksession):
<code>
logger.debug(">>> register transaction synchronization");
ksession.execute(new CMTDisposeCommand());
</code>
3. create and register a new class, CMTProcessEventListener, to listen for the process
complete event (code attached below)
<code>
CMTProcessEventListener procEventListener = new
CMTProcessEventListener(procInstance.getId(),ejbName);
logger.debug(">>> add process events listener");
ksession.addEventListener(procEventListener);
</code>
4. start the process instance execution:
<code>
logger.debug(">>> start the process instance");
ksession.startProcess(procInstance.getProcessId());
</code>
5. at this point, i've implemented a cycle in my code to wait until the
procEventListener.isProcessCompleted() is true before terminate the ejb method.
The jBPM engine notify the CMTProcessEventListener after the process complete, timer
included, the EJB method ends so the ejb container commits the transaction and call the
afterCompletion method so i can dispose che session.
Thank you very much Jiri, hope this help someone else too.
Umberto
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/824964#824964]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]