Executing Async task in not working

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2015 07:29 AM
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
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
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2015 03:36 AM
Hi Mohit,
following link could help you:
http://activiti.org/userguide/index.html#exclusiveJobs
Regards
Martin
following link could help you:
http://activiti.org/userguide/index.html#exclusiveJobs
Regards
Martin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2015 02:46 AM
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
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
AsyncJava.txt.zip
1 KB
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2015 07:37 AM
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.
<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.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2015 02:33 AM
Thanks very much for explaining the correct usage.
