I am running several subtasks in parallel with Ant.
This is the simplified content of build.xml:
<target name="parallelOperations">
<var name="port.number" value="9006"/>
<for list="a,b,c,d,e" param="letter" parallel="true">
<sequential>
<echo>Letter @{letter}</echo>
<math result="port.number" operand1="${port.number}" operation="+" operand2="1" datatype="int"/>
<echo>${port.number}</echo>
</sequential>
</for>
</target>
This is the main result:
[echo] Letter c
[echo] Letter b
[echo] Letter a
[echo] Letter d
[echo] Letter e
[echo] 9007
[echo] 9007
[echo] 9007
[echo] 9007
[echo] 9007
What happens here is for each element of the list, it prints the content of the element and the result of plus operation. The problem here is the math operation is not thread-save, means that every operation accesses the variable $port.number concurrently, adds one value, and then assigns the value.
Is there anyway to do it thread-safe with Ant? What I try to do is per each subtask which runs in parallel, get an unique port number. If there is any other way to do it, it could be also good solution.