<!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="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss 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;">
Duplicate tasks created after completing previous task
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/ciberg">João Guerra</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/832447#832447">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, I have a web application using JBPM 5.4 and the processes have only human tasks.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Sometimes when a task is completed JBPM creates the next task in the workflow in duplicate.</p><p>It seems that this is aggravated when multiple users are using the application.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>This is the code that I use to complete a task:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="font-size: 11px; font-family: Monaco;">          BlockingTaskOperationResponseHandler responseHandler = <span style="color: #931a68;">new</span> BlockingTaskOperationResponseHandler();</p><p style="font-size: 11px; font-family: Monaco;">                    <span style="color: #931a68;">try</span> {</p><p style="font-size: 11px; font-family: Monaco;">                              Task task = <span style="color: #0326cc;">taskService</span>.getTask(taskId);</p><p style="font-size: 11px; font-family: Monaco;">                              TaskData taskData = task.getTaskData();</p><p style="font-size: 11px; font-family: Monaco;">                              <span style="color: #0326cc;">humanTaskClient</span>.complete(taskId, user, <span style="color: #931a68;">null</span>, responseHandler);</p><p style="font-size: 11px; font-family: Monaco;">                              responseHandler.waitTillDone(75000);</p><p style="font-size: 11px; font-family: Monaco;">                              StatefulKnowledgeSession ksession = JBPMConnectionsInitializer.accessKnowledgeSession(processPackage);</p><p style="font-size: 11px; font-family: Monaco;">                              KnowledgeRuntimeLogger logger = JBPMConnectionsInitializer.activateKnowledgeRuntimeLog(ksession);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="font-size: 11px; font-family: Monaco;">                              <span style="color: #931a68;">new</span> JPAWorkingMemoryDbLogger(ksession);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="font-size: 11px; font-family: Monaco;">                              ksession.getWorkItemManager().completeWorkItem(</p><p style="font-size: 11px; font-family: Monaco;">                                                  taskData.getWorkItemId(), <span style="color: #931a68;">null</span>);</p><p style="font-size: 11px; font-family: Monaco;">                              logger.close();</p><p style="font-size: 11px; font-family: Monaco;">  ...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>This is the connection initializer:</p><p style="font-size: 11px; font-family: Monaco;">          <span style="color: #931a68;">public</span> <span style="color: #931a68;">static</span> StatefulKnowledgeSession accessKnowledgeSession(String processPackage) <span style="color: #931a68;">throws</span> Exception {</p><p style="font-size: 11px; font-family: Monaco;">                    KnowledgeBase kbase = <span style="color: #931a68;">null</span>;</p><p style="font-size: 11px; font-family: Monaco;">                    StatefulKnowledgeSession ksession = <span style="color: #931a68;">null</span>;</p><p style="font-size: 11px; font-family: Monaco;">                    EntityManagerFactory emf = Persistence.createEntityManagerFactory(<span style="color: #0326cc;">PERSISTANCE_ENTITY_NAME</span>);</p><p style="font-size: 11px; font-family: Monaco;">                    Environment env = KnowledgeBaseFactory.newEnvironment();</p><p style="font-size: 11px; font-family: Monaco;">                    env.set(EnvironmentName.<span style="color: #0326cc;">ENTITY_MANAGER_FACTORY</span>, emf);</p><p style="font-size: 11px; font-family: Monaco;">                    kbase = readJbpmKnowledgeBase(processPackage);</p><p style="font-size: 11px; font-family: Monaco;">                    ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, <span style="color: #931a68;">null</span>, env);</p><p style="font-size: 11px; font-family: Monaco;">                    <span style="text-decoration: line-through;">CommandBasedHornetQWSHumanTaskHandler</span> humanTaskHandler = <span style="color: #931a68;">new</span> CommandBasedHornetQWSHumanTaskHandler(ksession);</p><p style="font-size: 11px; font-family: Monaco;">                    humanTaskHandler.setConnection(<span style="color: #0326cc;">HUMAN_TASK_SERVER_HOST</span>,<span style="color: #000000;"> </span>HUMAN_TASK_SERVER_PORT<span style="color: #000000;">);</span></p><p style="font-size: 11px; font-family: Monaco;">          ksession.getWorkItemManager().registerWorkItemHandler(<span style="color: #3933ff;">"Human Task"</span>,humanTaskHandler);</p><p style="font-size: 11px; font-family: Monaco;">                    <span style="color: #931a68;">return</span> ksession;</p><p style="font-size: 11px; font-family: Monaco;">          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The tasks are started with this:</p><p style="font-size: 11px; font-family: Monaco;">                    BlockingTaskOperationResponseHandler responseHandler = <span style="color: #931a68;">new</span> BlockingTaskOperationResponseHandler();</p><p style="font-size: 11px; font-family: Monaco;">                    <span style="color: #931a68;">try</span> {</p><p style="font-size: 11px; font-family: Monaco;">                              <span style="color: #0326cc;">humanTaskClient</span>.start(taskId, user, responseHandler);</p><p style="font-size: 11px; font-family: Monaco;">                              responseHandler.waitTillDone(75000);</p><p>    ...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Can you please tell me what is wrong and how can I solve this.</p><p>Maybe this is happening because I'm not disposing of the ksession, but if I do that the application fails after completion of the task with a session not available error because it was disposed of.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/832447#832447">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://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>