<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Is the simple fork/join with async execution paths broken in jBPM 4.0
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/manjuss">Manjunath Somashekar</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/535670#535670">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>hi All,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We are exploring the simple fork/join construct for an usecase where in the execution path of each of the fork's branch has to be asynchronous. I have provided all the necessary details below, please do let me know if i am missing some thing very fundamental. This seems like a very fundamental usecase and may be we are missing just some very fundamental, please do let us know.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>Issue faced:</strong></em></p><p>The fork node starts the execution of both the branches in parallel by using inbuilt jBPM messaging. We have observed that the job executor picks up both the jobs and starts executing them concurrently. However the workflow never enters the join state.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>Environment:</strong></em></p><p>OS: Linux/Windows</p><p>Java: 1.5.0_22</p><p>jBPM: latest stable 4.0 release from sourceforge.</p><p>Executed as a simple JUnit testcase.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>Problem definition:</strong></em></p><p>We have a bunch of very long running processes that we want to execute in parallel. Once all these parallel processes are done we would like to continue with the workflow. We are trying to model this using fork/join and async continuation.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We are trying to execute the test cases provided in jBPM 4.0 with some minor modifications. For the prototype we are simulating long running processes as simple java nodes. The workflow definition is as follows:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>process.jpdl.xml:</strong></em></p><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>&lt;process name="AsyncFork" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.0/jpdl" target="_blank">http://jbpm.org/4.0/jpdl</a><span>"&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;start g="22,69,80,40"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition to="fork1" /&gt;<br/>&#160;&#160;&#160; &lt;/start&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;fork g="99,68,80,40" name="fork1"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition g="122,41:" to="ship goods" /&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition g="123,142:" to="send bill" /&gt;<br/>&#160;&#160;&#160; &lt;/fork&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;java class="org.jbpm.examples.async.fork.Application" g="159,17,98,50"<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; method="shipGoods" name="ship goods" continue="async"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition g="297,42:" to="join" /&gt;<br/>&#160;&#160;&#160; &lt;/java&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;java class="org.jbpm.examples.async.fork.Application" g="159,117,98,50"<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; method="sendBill" name="send bill" continue="async"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition g="297,141:" to="join" /&gt;<br/>&#160;&#160;&#160; &lt;/java&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;join g="274,66,80,40" name="join"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition to="print join" /&gt;<br/>&#160;&#160;&#160; &lt;/join&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;java g="159,117,98,50"<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; method="printjoin" name="print join"&gt;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition g="297,141:" to="end" /&gt;<br/>&#160;&#160;&#160; &lt;/java&gt;<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; &lt;end g="353,67,48,48" name="end" /&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;/process&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>Application.java: (Note: We have just modified the given java file)</strong></em></p><p>package org.jbpm.examples.async.fork;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.io.Serializable;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>/**<br/> * @author Tom Baeyens<br/> */<br/>public class Application implements Serializable {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private static final long serialVersionUID = 1L;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void shipGoods() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // assume automatic calculations here<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (int i = 10; i &gt; 0; i--) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Shipping goods");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sleep();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void printjoin() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Joining both the forked execution paths");<br/>&#160;&#160;&#160; }<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; private void sleep() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Thread.sleep(1000);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (InterruptedException e) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void sendBill() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // assume automatic calculations here<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (int i = 10; i &gt; 0; i--) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("New:Sending bill");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sleep();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; }<br/>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>AsyncForkTest.java:<em><strong>(Note: We have just modified the given java file)</strong></em></strong></em></p><p>package org.jbpm.examples.async.fork;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.util.Date;<br/>import java.util.List;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import org.jbpm.api.Execution;<br/>import org.jbpm.api.ProcessInstance;<br/>import org.jbpm.api.job.Job;<br/>import org.jbpm.test.JbpmTestCase;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/>/**<br/> * @author Tom Baeyens<br/> */<br/>public class AsyncForkTest extends JbpmTestCase {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; String deploymentId;<br/>&#160; <br/>&#160; protected void setUp() throws Exception {<br/>&#160;&#160;&#160; super.setUp();<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; deploymentId = repositoryService.createDeployment()<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addResourceFromClasspath("org/jbpm/examples/async/fork/process.jpdl.xml")<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; .deploy();<br/>&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; protected void tearDown() throws Exception {<br/>//&#160;&#160;&#160; repositoryService.deleteDeploymentCascade(deploymentId);<br/>&#160;&#160;&#160; <br/>//&#160;&#160;&#160; super.tearDown();<br/>&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; public void testAsyncFork() {<br/>&#160;&#160;&#160; ProcessInstance processInstance = executionService.startProcessInstanceByKey("AsyncFork");<br/>&#160;&#160;&#160; String processInstanceId = processInstance.getId();<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; System.out.println("processInstanceId: " + processInstanceId);<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; while (true) {&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160; }<br/>&#160;&#160;&#160; <br/>//&#160;&#160;&#160; List&lt;Job&gt; jobs = managementService.createJobQuery()<br/>//&#160;&#160;&#160;&#160;&#160; .processInstanceId(processInstanceId)<br/>//&#160;&#160;&#160;&#160;&#160; .list();<br/>//<br/>//&#160;&#160;&#160; assertEquals(2, jobs.size());<br/>//&#160;&#160;&#160; <br/>//&#160;&#160;&#160; Job job = jobs.get(0);<br/>//<br/>//&#160;&#160;&#160; managementService.executeJob(job.getId());<br/>//&#160;&#160;&#160; <br/>//&#160;&#160;&#160; job = jobs.get(1);<br/>//<br/>//&#160;&#160;&#160; managementService.executeJob(job.getId());<br/>//<br/>//&#160;&#160;&#160; Date endTime = historyService<br/>//&#160;&#160;&#160;&#160;&#160; .createHistoryProcessInstanceQuery()<br/>//&#160;&#160;&#160;&#160;&#160; .processInstanceId(processInstance.getId())<br/>//&#160;&#160;&#160;&#160;&#160; .uniqueResult()<br/>//&#160;&#160;&#160;&#160;&#160; .getEndTime();<br/>//<br/>//&#160;&#160;&#160; assertNotNull(endTime);<br/>&#160; }<br/>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>jbpm.cfg.xml: We have enabled jobexecutor.</strong></em></p><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;jbpm-configuration&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; &lt;import resource="jbpm.default.cfg.xml" /&gt;<br/>&#160; &lt;import resource="jbpm.tx.hibernate.cfg.xml" /&gt;<br/>&#160; &lt;import resource="jbpm.jpdl.cfg.xml" /&gt;<br/>&#160; &lt;import resource="jbpm.identity.cfg.xml" /&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; &lt;!-- Job executor is excluded for running the example test cases. --&gt;<br/>&#160; &lt;!-- To enable timers and messages in production use, this should be included. --&gt;<br/>&#160; &lt;import resource="jbpm.jobexecutor.cfg.xml" /&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; &lt;import resource="jbpm.mail.templates.examples.xml" /&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;/jbpm-configuration&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em><strong>Our Observations and Analysis:</strong></em></p><ul><li>2 jobs gets created in the JBPM4_JOB table one each for the async execution path</li><li>Job executor picks up both these jobs concurrently and starts executing the java action</li><li>With debugger on what i have noticed is that each of the job executor threads loads up the ExecutionImpl object into the hibernate session at the start of the execution and rarely hits the DB back for obvious performance reasons.</li><li>ExecutionImpl object is loaded at the start of thread execution, any of the state changes made by other job executor thread is not visible in the current thread unless the hibernate object is reloaded and this never happens as its a separate hibernate session and thread of execution.</li><li>Each of the execution paths tries to execute the JoinActivity</li><li>In the JoinActivity there is a check to see if all the branches have completed - this test fails always, hence workflow is in an indefinite wait state kind of a thing.</li><li>Join is not executed.</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks</p><p>Manju</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/535670#535670">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>