cancel
Showing results for 
Search instead for 
Did you mean: 

Java Service task to looping to call another java service task

bhola
Champ in-the-making
Champ in-the-making
Hi ,

I am new to Activiti and trying to create a POC , to call several java service tasks to under one java service task.

In details –

Start -> Java service Task 1- > Java Service Task 2 -> Java Service Task 3 -> End

For JST 1 I am calling a execute method of a java class which implements JavaDelegation  interface. Inside that I am trying to get a list of Objects from one external resource. I want to loop through the list of objects and call JST2, JST3 and pass each object as argument to them so that I can do some other operations in it.

Can you please help me , if there is any way to achieve this.

Thanks in advance Smiley Happy
Bhola
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
Have a look at multi-instance characteristics (see userguide). This allows you to repeat a single service-task multiple times, based on a collection of values. These values can be stored as a process-variables, based on a step before or just based on an expressions which resolves to a service-call.
The tricky part is to connect the right "behaviour" to the service-task invocation.

Another alternative is to just execute the JavaDelegate from within the code (as you whould call any code) or event call your own interface-methods on each of the different operations you want to perform. This will only show one service-task in the history offcourse, so not as optimal as the multi-instance approach, which can even be made asynchronous.

bhola
Champ in-the-making
Champ in-the-making
Hi Frederik,

Thanks alot for the suggestions..

I would like to implement a 'Java Receive Task' as my first activity which will wait till it gets a Message object of type Transaction from a queue. After that I want to use that Message and proceed with other activities.

As I am new to this I don't find much details in user guide regarding the Recieve task approach can you please help if you have any steps on how to implement.

And one more thing I want to know.. How can I make my activiti project keep on running so that it will be executed whenever a message receives and how can I call the my activiti from other application?

Please help me on this.

jbarrez
Star Contributor
Star Contributor
> the Recieve task approach can you please help if you have any steps on how to implement.

The receive task + signal is very easy: your process goes into a wait state (receive task). It has an execution pointing to it. Something external calls the runTimeService.signal(executionId) method and your process will continue. To send out the execution id, you can use for example your own service task or an execution listener that sends out the executionId to some queue for example.

> How can I make my activiti project keep on running so that it will be executed whenever a message receives and how can I call the my activiti from other application

See above, you call the Java API (or REST if you're using that) with the signal method.