Here is an example that shows how to process a loop using JBPM5.

A simple example shown in the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here.

This example has two parameters ‘count’ and ‘loopcondition’.

The paramter ‘count’ gets incremented in a loop until it is less than a ‘loopcondition’.

 

ScreenHunter_09 Mar. 01 09.41.gif

 

ScreenHunter_05 Mar. 01 20.34.gif

How to run this example?

 

This example has a bpmn file (looptest777.bpmn) and a test file (ProcessTest2.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

 

ScreenHunter_03 Mar. 01 20.16.gif

 

Here is the sample test code. The main process ‘looptest777’  is started as shown below.

 

 

public static final void main(String[] args) {
  try {
   // load up the knowledge base
   KnowledgeBase kbase = readKnowledgeBase();
   StatefulKnowledgeSession ksession = createSession(kbase);
   KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
     .newFileLogger(ksession, "test");

   // set the parameters
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("count", 1);
   params.put("loopcondition", 3);
  
   // start a new process instance
   ksession.startProcess("looptest777", params);
  
   logger.close();
  } catch (Throwable t) {
   t.printStackTrace();
  }
}

 

Following output can be seen after running the example.

ScreenHunter_04 Mar. 01 20.18.gif