[jboss-user] [JBoss jBPM] - Re: TaskInstance.end() hogs CPU time

Johan.Parent do-not-reply at jboss.com
Thu Jan 11 09:47:39 EST 2007


Hi Koen,

Many thanks for your answer!

You're are right of course, below the relevant code and definition.

I've run into the exact same problem using a HSQLDB as well as a Sybase backend.

The process definition is (IMHO) simple:


  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <process-definition xmlns="urn:jbpm.org:jpdl-3.1"  name="oe_process">
  |    <swimlane name="Prescriber">
  |           <assignment expression="user(doc1)"></assignment>
  |    </swimlane>
  | 
  |    <swimlane name="OrderEntryPeople">
  |            <assignment expression="user(oe1)" />
  |    </swimlane>
  | 
  |    <start-state name="Prescribe">
  | 	  <task swimlane='PrescriberTask' />
  |       <transition name="" to="Oe">
  |       </transition>
  |    </start-state>
  | 
  |     <task-node name="Oe">
  |        <task name="OeTask" swimlane="OrderEntryPeople">
  |        </task>
  |        <transition name="" to="Sign"></transition>
  |     </task-node>
  | 
  | 
  |    <task-node name="Sign">
  |       <task name="SignTask" swimlane="Prescriber"></task>
  |       <transition name="" to="end"></transition>
  |    </task-node>
  | 
  |     <end-state name="end"></end-state>
  | 
  | </process-definition>
  | 

As is the actual client code that consumes all the CPU time:


  |     public void processHandle(String processName) {
  |         // The code in this method could be the content of a message driven bean.
  | 
  |         // Lookup the pojo persistence context-builder that is configured above
  |         createSession();
  | 
  |         System.out.println(jbpmContext.getActorId());
  | 
  |         try {
  |             jbpmContext.setActorId(actorName);
  | 
  |             // First, we need to get the process instance back out of the database.
  |             // There are several options to know what process instance we are dealing
  |             // with here.  The easiest in this simple test case is just to look for
  |             // the full list of process instances.  That should give us only one
  |             // result.  So let's look up the process definition.
  | 
  |             ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition(processName);
  | 
  |             // Now we search for all the tasks waiting for our actor
  |             List tasksActor = taskMgmtSession.findTaskInstances(actorName);
  | 
  |             if (verboseFlag)
  |                 System.out.println("ID: " + id + " got " + tasksActor.size() + " tasks waiting");
  | 
  |             if (tasksActor.size() > 0) {
  |                 for (int i=0; i<tasksActor.size(); i++) {
  |                     TaskInstance instance = (TaskInstance) tasksActor.get(i);
  | 
  |                     if (verboseFlag) {
  |                         System.out.println("ID: " + id + " Token positioned in " + instance.getName() + " " + instance.getId());
  |                         System.out.println("Values: " + instance.getVariable("userName") + " " + instance.getVariable("UUID") );
  |                     }
  | 
  |                     // Skip already finished instances
  |                     if (instance.hasEnded()) {
  |                         System.out.println("Tasks has already been processed. CHECK THIS!!!!");
  |                     } else {
  |                         // Now we can do our work here and mark the end of this task
  |                         instance.end();
  |                     }
  | 
  |                     // Now we can update the state of the execution in the database
  |                     jbpmContext.save(instance);
  |                 }
  |             }
  |         } finally {
  |             // Tear down the pojo persistence context.
  |             closeSession();
  |         }
  |     }
  | 

To be complete I'll add the utility methods too:


  |     protected void createContext() {
  |         jbpmContext = jbpmConfiguration.createJbpmContext();
  |     }
  | 
  |     protected void closeContext() {
  |         jbpmContext.close();
  |     }
  | 
  |     protected void createSession() {
  |         createContext();
  |         initializeMembers();
  |     }
  | 
  |     protected void closeSession() {
  |         closeContext();
  |         resetMembers();
  |     }
  | 
  |     protected void initializeMembers() {
  |       session = jbpmContext.getSession();
  |       graphSession = jbpmContext.getGraphSession();
  |       taskMgmtSession = jbpmContext.getTaskMgmtSession();
  |       schedulerSession = jbpmContext.getSchedulerSession();
  |       contextSession = jbpmContext.getContextSession();
  |     }
  | 
  |     protected void resetMembers() {
  |       session = null;
  |       graphSession = null;
  |       taskMgmtSession = null;
  |       schedulerSession = null;
  |       contextSession = null;
  |     }
  | 


Additional runs show that the observed decrease in performance (aka cpu hogging) coincides with a rapid increase in mem usage. I wonder whether I'm using the jbpm api correctly.

Regards,

Johan

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4000471#4000471

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4000471



More information about the jboss-user mailing list