[jboss-user] [jBPM] - Workitem handler thread safety issues

hua zhong do-not-reply at jboss.com
Wed Jun 6 03:52:49 EDT 2012


hua zhong [https://community.jboss.org/people/ghuazh] created the discussion

"Workitem handler thread safety issues"

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

--------------------------------------------------------------
Hi, all.

Human workitem handler need be resigted to ksession before human task process start.

I need to pass some object into workitem handler, but it's not tread safety.

code:

CommonSingleObjectWorkHandler handler = new SingleObjectWorkHandler(ksession);
handler.setSingleObject(so);

In handler:

setSingleObject(ISingleObject so){
 this.so = so;
}

and in executeWorkItem method, we have code to use "so".

@Override
    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
        Task task = createTaskBasedOnWorkItemParams(workItem);
        ContentData content = createTaskContentBasedOnWorkItemParams(workItem);
        connect();
        try {
            getClient().addTask(task, content);
            String userId = (String) workItem.getParameter("ActorId");
            //...we use "so" here............................................
        } catch (Exception e) {
            if (action.equals(OnErrorAction.ABORT)) {
                manager.abortWorkItem(workItem.getId());
            } else if (action.equals(OnErrorAction.RETHROW)) {
                if (e instanceof RuntimeException) {
                    throw (RuntimeException) e;
                } else {
                    throw new RuntimeException(e);
                }
            } else if (action.equals(OnErrorAction.LOG)) {
            }
            e.printStackTrace();
        }


But the handler will be used by other session. and invoke the setSingleObject()  mothod to make data changed.

We have only one method to start process, and every time it'll create a new ksession and handler.
I don't know the reason why the handler will shared in those sessions?


To solve this problem, we need to pass "singleObject" to a process parameter, in executeWorkItem() method get the "singleObject" from workitem parameter.


h3.  http://www.zeropaid.com/bbs/threads/6765-i-hope-this-is-the-last-problem-i-ever-get-and-the-final-solution http://www.zeropaid.com/bbs/threads/6765-i-hope-this-is-the-last-problem-i-ever-get-and-the-final-solution
--------------------------------------------------------------

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120606/c5912d76/attachment.html 


More information about the jboss-user mailing list