I have trace the code in CommandBasedWSHumanTaskHandler. I find that the KnowledgeRuntime pass in constructor is used by the callback handler in GetCompletedTaskResponseHandler and GetResultContentResponseHandler only. I remove that in constructor and add method registerHumanTaskSession(Long pTaskId, KnowledgeRuntime pSession) and deregisterHumanTaskSession(Long pTaskId) in it. Before I call TaskClient.completeTask, I first registerr the task id and correponding session in the CommandBasedWSHumanTaskHandler. In the callback, I change session.getWorkItemManager().completeWorkItem(workItemId, results) to sessionLookup.get(task.getId()).getWorkItemManager().completeWorkItem(workItemId, results);
In this way I can share the TaskClient and BlockingComamndBasedWSHumanTaskHandler by multiple process instance.
Also in the connect method,
I configure a flag and only let the registerForEvent execute once only. Otherwise multiple callback will be triggered since executeWorkItem call connect method implicitly.
I have tested this under 10 concurrent thread and seems having no problem in this way. But I am not sure if using a single TaskClient in BlockingCommandBasedWSHumanTaskHandler amongs all process instance affects performance.
IsRemove interface tells if the handler is removed after the process of callback message. TaskCompletedHandler isRemove() always return false so I think it is meant to be reused and initialized once only.