cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Async task in not working

mohitsrivastava
Champ in-the-making
Champ in-the-making
Hi,

I am trying to execute an async task. But it is not running.

My requirement is servicetask2 should execute while servicetask1 is still in progress.

I did the following. Please have a look at the files I used.:

1. BPMN File(Only relevant part shown):

  <process id="Async" name="Async" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask1" name="AsyncProcess" activiti:async="true" activiti:class="com.demo.JavaAsyncTask"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="servicetask2" name="NormalProcess" activiti:class="com.demo.JavaNormalTask"></serviceTask>
    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="endevent2"></sequenceFlow>
  </process>

2. Java class 1:

public class JavaAsyncTask implements JavaDelegate{
   public void execute(DelegateExecution execution) throws Exception {
      System.out.println("Java Async Task Started");
      Thread.sleep(60000);
      System.out.println("Java Async Task End");
   }
}

3.Java Class 2:

public class JavaNormalTask implements JavaDelegate{
   public void execute(DelegateExecution execution) throws Exception {
      System.out.println("Java Normal Task Started");
      System.out.println("Java Normal Task End");
   }
}


4. I created jar and copied in lib directory of tomcat.

5. Now on doing Start Process in Activiti Explorer Nothing happens. Nothing is displayed in log(catalina.out)

6. But when I removed activiti:async="true" from BPMN file. Then the values specified in system.out are displayed in log.

So could you please suggest how to use this async=true. Any more configuration is required?

Thanks and Regards
Mohit Srivastava

4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Mohit,

following link could help you:
http://activiti.org/userguide/index.html#exclusiveJobs

Regards
Martin

mohitsrivastava
Champ in-the-making
Champ in-the-making
Hi Martin,

Thanks for your reply.
But it is still not working. The service tasks are executing in sequence. Please have look at the code below:

1. BPMN File.

Attached as txt file.


Java Class 1 For Async execution:

public class AsyncJavaShellScript implements JavaDelegate {

public void execute(DelegateExecution execution) throws Exception {
  System.out.println("Async Shell Script through Java start");
  executeShellScript();
}

private void executeShellScript() {
  try {
      ProcessBuilder pb = new ProcessBuilder("/home/impadmin/ACTIVITI/AsyncScript.sh");
      Process p = pb.start();     // Start the process.
      p.waitFor();                // Wait for the process to finish.
      System.out.println("Async Script executed successfully");
    } catch (Exception e) {
     e.printStackTrace();
    } 
}

}


Java Class 2 For normal execution:

public class NormalJavaShellScript implements JavaDelegate {

public void execute(DelegateExecution execution) throws Exception {
  System.out.println("Normal Shell Script through Java start");
  executeShellScript();
}

private void executeShellScript() {
  try {
      ProcessBuilder pb = new ProcessBuilder("/home/impadmin/ACTIVITI/NormalScript.sh");
      Process p = pb.start();     // Start the process.
      p.waitFor();                // Wait for the process to finish.
      System.out.println("Normal Script executed successfully");
    } catch (Exception e) {
     e.printStackTrace();
    } 
}

}





3. AsyncScript.sh

echo 'Async Activiti Script' $(date +%x_%r) >> /home/impadmin/ACTIVITI/AsyncScriptOutput1.txt
echo 'Sleeping' $(date +%x_%r) >> /home/impadmin/ACTIVITI/AsyncScriptOutput1.txt
sleep 20
echo 'Awake' $(date +%x_%r) >> /home/impadmin/ACTIVITI/AsyncScriptOutput1.txt




4. NormalScript.sh
echo 'Small Activiti Script' $(date +%x_%r) >> /home/impadmin/ACTIVITI/SmallScriptOutput1.txt

Could you please advice so that servicetask2 starts without waiting for servicetask1 to complete.

Thanks
Mohit

jbarrez
Star Contributor
Star Contributor
Looking at your process xml, it's logical they are not in parallel:
<code>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
</code>

service task 2 simply follows after service task 1.

Add a parallel gateway before the two service tasks. Make them both async. You'll get what you want.

mohitsrivastava
Champ in-the-making
Champ in-the-making
Thanks very much for explaining the correct usage.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.