Swaminathan Bhaskar [https://community.jboss.org/people/swaminathan.bhaskar] 
created the discussion

"Re: Work Item not persisted"

To view the discussion, visit: https://community.jboss.org/message/760862#760862

--------------------------------------------------------------
Finally works ... Made some code adjustments to launch a thread from the 
CustomWorkItemHandler and pass the KnowledgeSession as follows:

import org.drools.runtime.process.*;

public class CustomWorkItemTask implements Runnable {
    private WorkItem item;
    private WorkItemManager manager;

    public CustomWorkItemTask(WorkItem item, WorkItemManager manager) {
        this.item = item;
        this.manager = manager;
    }

    @Override
    public void run() {
        System.out.printf("\n-----> Waiting in custom work item %s <ID:%d> for 
60 secs\n", item.getName(), item.getId());

        // Artificial wait
        try {
            Thread.sleep(60000);
        }
        catch (Exception ex) {
        }

        System.out.printf("\n-----> Completing custom work item %s <ID:%d>\n", 
item.getName(), item.getId());

           manager.completeWorkItem(item.getId(), null);
    }
}

// -------------------------------------------------------------


import org.drools.runtime.*;
import org.drools.runtime.process.*;

public class CustomWorkItemHandler implements WorkItemHandler {
    private KnowledgeRuntime ksession;

    public CustomWorkItemHandler(KnowledgeRuntime session) {
        this.ksession = session;
    }

    @Override
    public void executeWorkItem(WorkItem item, WorkItemManager manager) {
*        // NOTE: Cannot use the WorkItemManager passed into the method - It 
will throw the following exception:*
*        //       javax.persistence.TransactionRequiredException: No active JTA 
transaction on joinTransaction call*

        CustomWorkItemTask task = new CustomWorkItemTask(item, 
ksession.getWorkItemManager());

        new Thread(task).start();
    }

    @Override
    public void abortWorkItem(WorkItem item, WorkItemManager manager) {
    }
}

Hope this is helpful for someone
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/760862#760862]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to