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-...
http://www.zeropaid.com/bbs/threads/6765-i-hope-this-is-the-last-problem-...
--------------------------------------------------------------
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&...]