Parallel Gateway working

Hi,

I am very beginner to Flowable. I have a requirement to execute two service tasks in parallel (concurrent execution) and then join their results. So I am using a parallel gateway to fork two service tasks and then join them through another gateway. The figure is uploaded. However, I always see “Form Order” task executes first and then “Branch Task” in sequence. I was expecting them to execute in concurrent way. Is my understanding wrong or I am missing anything.

The parallel gateways are made their “Exclusive” properties ON.
The service tasks are made their “Exclusive” properties ON.
None are made asynchronous.

Looking for your help. Thanks.

Process

Saby

Hi Saby,

A process instance is by default executed in one thread. So when using a parallel gateway, you will see the first task being executed and then the second. This is to prevent possible concurrency issues. If you want to execute them in different threads in parallel then you need to define the tasks as asynchronous and exclusive = false. Then the job executor will execute the tasks in different threads in parallel. Be aware that you could have concurrency issues if the tasks set variables in the process instance execution for example. Then you will see optimistic lock exceptions. Also make sure you set the joining parallel gateway to async as well in this case and exclusive = true.

Best regards,

Tijs

2 Likes

Thanks Tijs for your response. I will change this accordingly and get back.

Regards,
Saby

Hi Tijs,

First of all thanks once again for your information. The parallel threads seems working by using asyncExecutor. However, I am facing few problems and looking for your help for those.

The design diagram is same as given earlier. The configuration is given as:
++++++++++++++++++++++++++++++++
bpmn_sample
++++++++++++++++++++++++++++++

The sample code:
++++++++++++++++++++

  {
       ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
       .setJdbcUrl("jdbc:mysql://172.28.1.140:3306/flowable?autoReconnect=true")
       .setJdbcUsername("flowable")
       .setJdbcPassword("flowable")
       .setJdbcDriver("com.mysql.jdbc.Driver")
       .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
       cfg.setAsyncExecutorActivate(true);

       ProcessEngine processEngine = cfg.buildProcessEngine();
		AsyncExecutor aE = cfg.getAsyncExecutor();
		//aE.start();

		System.out.println("########## Process Engine Object creation completed....");

		//Deploying a process definition 
		RepositoryService repositoryService = processEngine.getRepositoryService();
		Deployment deployment = repositoryService.createDeployment()
		.addClasspathResource("jobexec.bpmn20.xml.bpmn")
		.deploy();

		System.out.println("Process Definition id:"+ deployment.getId());

		ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
			  .deploymentId(deployment.getId())
			  .singleResult();
			System.out.println("Found process definition : " + processDefinition.getName());		    

		System.out.println("########## Deploying a process definition completed....");
	    	
  		Scanner scanner= new Scanner(System.in);
  		
		System.out.println("Enter a string");
		  
		String inputStr = scanner.nextLine();
	
		RuntimeService runtimeService = processEngine.getRuntimeService();

		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("inputStr", inputStr);
		  
		ProcessInstance processInstance =
		runtimeService.startProcessInstanceByKey("myProcess", variables);
		
		//aE.shutdown();
  }

++++++++++++++++
Now, should I have to start and shutdown the asyncExecutor?
If I do then the “Service Task” after parallel join is not executing and the process dies.
If I don’t start the asyncExecutor then the “Service Task” is getting executed. Here I am confused. May be the process getting dead before task executes.
What should be the ideal configuration?

Also find the asyncExecutor properties…
asyncExecProperties

Looking forward for your reply.

Best Regards,
Saby