1 Reply Latest reply on Apr 28, 2012 2:13 AM by Sukumaran Raghavan

    Is SessionID & ProcessID required to complete WorkItem ?

    vikas jadon Newbie

      I have question about  ProcessID and SessionID and there usage. I will continue to ask after explaining the confusion areas. This is with respect to webapplication, used by multiple users and deployed in clustered env.



      EntityManagerFactory emf =  Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );

         env = KnowledgeBaseFactory.newEnvironment();

         env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );


      // create a new knowledge session that uses JPA to store the runtime state. Is this session for the server or I can create per user ? What is best?

      // i understand creation session per user will be costly


      ksession =   JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );

      sessionID = ksession.getId();  // i can persist this, 




      //starting the process, I think this is for each user

      pi1 =(WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.wfPOC",parameterMap);

      // i can get process id of the process started, so i am in the first workItem now.

      processID = pi1.getId(); // i can persist this too.

      // i have a method in my handler for getting the workItemId. i persisted this workItemId

      workItemId = my_handler_obj.getWorkItemId();


      At some time later I would like to complete the workItem, understanding the server is restarted


      // I can use JPAKnowledgeService.loadStatefulKnowledgeSession(persisted_sessionID, kBase, null, env); but following also works


      ksession =   JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );

      sessionID = ksession.getId();  // it is different session




      // I can complete workItem which was left earlier,


      ksession.getWorkItemManager().completeWorkItem(workItemId, null);


      My questions:


      1. What is the use of sessionID, since i can complete workItem without sessionID? is if useful in this scenerio ? (I can load the session)

      2. What is the use of processID since i can complete workItem without processID?? is it useful in this scenerio ? (i can start the process with process id)

      3. Is only workItemID sufficient to complete a workItem in realtime? or am i missing something

      4. How the knowledge session will work in case of clustered env across the JVM's using the load balancer.


      Any help is highly appreciated.




        • 1. Re: Is SessionID & ProcessID required to complete WorkItem ?
          Sukumaran Raghavan Newbie

          Hi Vikas,


          I have been using JBPM 5.2 in a similar environment. My understanding is as follows

            - Session ID: The session is a global repository where you store common data across processes. This comes into play only when you are using Rule (Which is why is is a knowledge repository). If you are using JBPM purely for execution of workflow (i.e. just graph execution), the JBPM session ID is not of much relavence. I would still recommend you use the same session ID to complete a work item (Just to keep the JBPM data consistent).

          - Process ID - This is a unique ID for each process instance. The nodes execute in the context of a process. Hence this is of relavence. When you complete a work item, the work item id is sufficient. This is because, the work item Tables in JBPM DB have a reference to the Process instance id. hence this is known to JBPM.

          - Work Item ID : Self explanatory i guess.


          Regarding how KSession works in a clustered environment. There are multipe approaches to this. What i have opted for is to use a separate KSession for each process instance. (Purely because i do not use any rules). Other approaches i have come across in the forums are to use a specific KSession for each server instance in your cluster. All processes that execute in a server will use the same ksession. Their process instances will be different.


          The approach you take should be based on how you are using JBPM.


          Happy working.. Its always hard for the first few who start using a new Technology. But i am sure its worth the effort


          Cheers !