3 Replies Latest reply on May 24, 2007 4:40 AM by clandestino_bgd

    cannot read process variable from other thread

    clandestino_bgd

      Hi JBPM people,
      I have the following Business requirement.
      Process looks like this:
      start-T1-S2-W3-T4-S5-J6-end
      "T1" is a task node
      Here should be specified how many paths of execution (document translations) will be performed concurrently.
      "S2" is a state which has some ForEachForkAction handler which creates particular number of tokens and creates some local variables
      "W3" is a wait state (in each token, task is waiting for free user from the pool). When user becomes available, token is signaled and task T2 is created for next available user.
      "T4" is a task node where user translates the document
      "S5" when user finishes the task it goes back to the pool
      "J6" join all tokens, when required number of resources (documents) are processed, process then ends.

      Here are the action classes used:
      in T1 on node-leave event there is action which sets process variable

      context.getContextInstance().setVariable("tokenCSVList", tokenCSVList);
      


      in S2 on node-enter event there is action which:
      - can read tokenCSVList (as expected)
      - create N tokens, depending on number of comma separated tokens
      - create local variable documentId for each new token
      - puts user Ids into JMS queue. Each user Id is one JMS message.

      for (int j=0; j<numberOfTokens; j++) {
       final Token newToken = new Token(rootToken, tokenNames[j]);
       newToken.setTerminationImplicit(true);
       context.getJbpmContext().getSession().save(newToken);
       final ExecutionContext newExecutionContext = new ExecutionContext(
       newToken);
       // create documentId for that token ....
       node.leave(newExecutionContext);
      }
      
       // put all available user Ids into JMS queue
       long processInstanceId = context.getProcessInstance().getId();
       for (int i=0; i<numberOfAnnotators; i++){
       messageProducer.sendMessage(userNames, processInstanceId);
       }
      


      Now, follows the problematic part.
      I have message consumer which should read process variable: tokenCSVList, but it simply cannot. i am getting NULL .
      String tokenCSVList = (String) processInstance
       .getContextInstance().getVariable(
       JPDLConstants.TOKEN_CSV_LIST);
      

      Also it cannot read new tokens created, only find root token.
      This is the original JBPM query in hibernate_queries.hbm.xml
      Query query = session.getNamedQuery("GraphSession.findTokensForProcessInstance");
       query.setEntity("processInstance", processInstance);
       List tokens = query1.list();
      


      I have checked DB: both variable and tokens are inserted.
      My question is WHY is that happening, or what could be the reason(s).

      Let me tell you about my configuration.
      i am using JBPM with springmodules.
      I have only one hibernate config file with both JBPM and my app hbm files
      JBPM tables and my app tables are in the same DB.
      single Hibernate session is used.
      I am using HashtableCache provider (tried also with noCache, but the same result)
      My Message Consumer and action handlers share the same JbpmConfig.
      I have configured OpenSessionInView hibernate filter.
      I thought that it may cause the problem, so I remove it. No change :(

      I am pretty confused, so any hint would mean a lot.
      Thanx
      Milan