cancel
Showing results for 
Search instead for 
Did you mean: 

Async service task not executing

afshad
Champ in-the-making
Champ in-the-making
If I have two starting tasks that are async = true and exclusive = false then it seems like Activiti starts neither of them. The delegate execute() method is never entered. When I call getActiveActivitiIds() as shown below, it returns me the first and second service task names and doesnt seem to quit.

            ProcessInstance proc = runtimeService.startProcessInstanceByKey(BPMNCreator.INSTANCE.getWorkflowProcessID());
            while(runtimeService.getActiveActivityIds(proc.getId()).size() > 0) {
                List<String> activeActivityIds = runtimeService.getActiveActivityIds(proc.getId());
                for(String str : activeActivityIds) {
                    System.out.println("Currently executing: "+str);
                }
                Thread.sleep(100);
            }
The xml flow:
<parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="parallelgateway1" targetRef="serviceTask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="parallelgateway1" targetRef="serviceTask2"></sequenceFlow>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow4" name="" sourceRef="serviceTask1" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="serviceTask2" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="parallelgateway2" targetRef="serviceTask3"></sequenceFlow>
   
<sequenceFlow id="flow7" sourceRef="serviceTask3" targetRef="endevent1"/>
<endEvent id="endevent1" name="End"/>

The loop above never stops and just prints the first and second service Task ids but never actually executes them.  I expect it to print all the service task ids and then break.
It works fine when i dont use a parallel gate way or async = true and have all three service tasks sequential order.
Whats could be going wrong? Why isnt it starting the tasks?

Thanks
9 REPLIES 9

trademak
Star Contributor
Star Contributor
Hi,

This is not the right way to write a test with the Activiti job executor.
Please look in the unit tests of the Activiti Engine itself how to implement this.
You can for example look at the boundary timer event tests.

Best regard,

afshad
Champ in-the-making
Champ in-the-making
Hi,

This is not the right way to write a test with the Activiti job executor.
Please look in the unit tests of the Activiti Engine itself how to implement this.
You can for example look at the boundary timer event tests.

Best regard,

Thanks for the reply Trademak.
I am not writing a test rather a working solution with Activiti as part of my project. Things work fine without the asynch tag but not with it.
If I use the tag, the service tasks dont run.
I looked under the examples and found the xml file BoundaryTimerEventTest.testInterruptingTimerDuration.bpmn20.xml
I dont see how this relates to my situation and also this xml has no service task. Also I could not find the java unit test to test this example.
Thanks

trademak
Star Contributor
Star Contributor
Hi,

Okay, then I misunderstood your question. Is it possible to create a unit test project so I can try to reproduce it?

Best regards,

jimk
Champ in-the-making
Champ in-the-making
I have a small example (but not a unit test) of a workflow with an async service task that isn't behaving as I'd expect.  See the attached Zip file.

This is a small workflow with two service tasks (actually the same task twice); the first service task is marked asynchronous.

What I expect:  See the first service task print its message to the console, then see the main thread print (several times) that the first task is executing, then see the second service task print its message, then see the main thread print that the second task is executing, then see the main thread print that the workflow has ended.

What I see:  I see the output from the two service tasks, but the main thread always says that the first task is the one that's executing.  In addition, ProcessInstance.isEnded() always returns false, so the main thread doesn't really know that the workflow has ended.  When the main thread ends the Java process doesn't terminate; apparently some Activiti thread is still hanging on.

trademak
Star Contributor
Star Contributor
Hi,

I've tested your project and have the following feedback:

1. The Activiti Engine actually does execute both serviceTask2 as well as serviceTask3.
2. The main thread is not stopped because you start the job executor with the Activiti Engine, and that's an infinite thread.
3. This is not the way you should test functionality that involves the job executor. For a good example see org.activiti.engine.test.bpmn.event.timer.BoundaryTimerEventTest and then the testExpressionOnTimer test method

How do you want to use the Activiti Engine in your production solution? Will it run as part of a webapp or standalone?

Best regards,

jimk
Champ in-the-making
Champ in-the-making
Hi Tijs,

Thanks for taking a look.

OK, I've got the infinite thread figured out.  I was neglecting to call ProcessEngine.close(), so that's fixed now.

What I'm trying to do is run the Activiti engine embedded in my application.  I want the workflow process to run in its own thread, and I want to be able to call RuntimeService.getActiveActivityIds() (or some other mechanism) to monitor the progress of the workflow process.

I read here in the forums that I could achieve this by marking the first task in my workflow as async, but in doing that I've run into two main problems:  1. getActiveActivityIds() always returns the ID of the first task in the workflow, even when that task has completed and the next task is executing.  2. ProcessInstance.isDone() never returns true, even when the last task in my workflow has completed.

Thanks again,
Jim

trademak
Star Contributor
Star Contributor
Hi,

And what type of application is this, a web application, a JSE application?
It matters a lot on how you are testing this functionality, because the test you attached in an earlier post isn't the right way to do this as I already said.
If you for example use the Activiti Explorer to run this example, it should just work fine. Did you try that?

Best regards,

jimk
Champ in-the-making
Champ in-the-making
Hi Tijs,

This is a JSE application.  I haven't tried the workflow in Activiti Explorer.

Thanks,
Jim

trademak
Star Contributor
Star Contributor
Hi Jim,

Could you please test the process with the Activiti Explorer first. Then you are sure that the functionality is working as expected.
The next step would then be to use the Activiti Engine in your JSE application.

Best regards,