0 Replies Latest reply on Jun 6, 2012 3:53 AM by hua zhong

    Workitem handler thread safety issues

    hua zhong Newbie

      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.