4

I'm trying to run parallel tasks on Ant.
User provide a list of server (-Drhosts="rhost1,rhost2,...") and the system should start the same target only using a different host each time.
<ac:for> and <ac:foreach> only support <sequential>, not <parallel>

Any idea?

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Assaf
  • 53
  • 1
  • 5

2 Answers2

9

It supports parallel running by specifying an property.

Parameters of Ant-contrib's <for> task:

parallel
If true, all iterations of the nested will execute in parallel. Defaults to false, which forces sequential execution of the iterations. It is up to the caller to ensure that parallel execution is safe.

threadCount
The maximum number of allowable threads when executing in parallel.

So if you can set parallel="true". Please note that there is nothing to do with the nested <sequential> element, because the tasks inside <sequential> are still executed sequentially; by setting parallel parameter, you tell <for> tasks to execute multiple <sequential>s at the same time -- how many? It depends on the number of elements in your list, as well as the value of threadCount.

Please check

http://ant-contrib.sourceforge.net/tasks/tasks/for.html

to see all the parameters.


And for <foreach> task, it executes the specified target for each element in your list, or each file in the nested fileset. You can also use parallel property to make the execution parallel.

Check

http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html

Dante WWWW
  • 2,729
  • 1
  • 17
  • 33
  • @user1633264 At least read the table of properties of the task. Also, plz click accept if this is the answer that helps you to sovle your problem. – Dante WWWW Aug 31 '12 at 09:06
  • Would be nice if you extend your answer with the information, how it should look like if the "list" contains names of other targets defined in build.xml. I found it only in https://stackoverflow.com/a/46299109/4807875 that it should be . – Alexander Samoylov Apr 01 '21 at 14:11
0

Here is the sample piece of code:

 <for list="some_list" param="list_param" delimiter="any_delimiter" parallel="true">
     <sequential>
        ...         
     </sequential>
 </for>
Sujith
  • 1,349
  • 1
  • 7
  • 12