JBoss Community

Re: Work Item not persisted

created by Swaminathan Bhaskar in jBPM - View the full discussion

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

Start a new discussion in jBPM at Community