JBoss Community

Re: jBPM5 - How to abort a already running ProcessInstance?

created by scurvo in jBPM - View the full discussion

Hi,

 

The way I solved it and according to my problem was:

 

1 - Create a Work Item handler and the work item with abort methods:

 

public class PrintWorkItemHandler extends MyWorkItemHandler {

    public Printer2 p;

    protected Date startTime;

    protected Date endTime;

 

    class printThread extends Thread {

 

 

        protected long wiID;

 

 

        public printThread(long wiID) {

            this.wiID = wiID;

        }

 

 

        public void run() {

            startTime = new Date();

            p = new Printer2();

            p.printAlot("adasd");

 

 

            // notify manager that work item has been completed

            mng.completeWorkItem(wiID, null);

            endTime = new Date();

            System.out.println("PRINT ENDED and took  " +

                            JBPMUtil.dateDiff(startTime, endTime));

        }

    }

 

 

    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

        super.addWorkItem(workItem);

        super.setWorkItemManager(manager);

 

 

        new printThread(workItem.getId()).start();

    }

 

 

    public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {

        System.out.println("ABORTED");

        p.stop = true;

        manager.abortWorkItem(workItem.getId());

    }

}

 

2 - When i want a workItem to finish i do:

 

mng.completeWorkItem(wiID, null); to complete ir

or

manager.abortWorkItem(workItem.getId()); to abort it

Reply to this message by going to Community

Start a new discussion in jBPM at Community