How to configure parallel tasks in ANT?

Ant is an acronym for "Another Neat Tool". The main function of Apache ANT is to convert your source code into executable code. The Ant file is in XML format so you can parse it according to the requirement. Here you can read about parsing. If you are completely new to the ANT tool you can read it here.

Now in today's time Ant is used all over the world and almost every company. It doesn't matter if you are a developer, tester, or DevOps person each profile has its own use regarding ANT.



Now Let's dive into what are the different ways to implement.


There are majorly three ways to parallelize your ANT build files:-


  • Adding Parallel tags in your Ant build file:-

<property name="disturbed">
    <attribute file="file"/>
   <sequential>
      <java jar="utils/abc.jar" fork="true" >
        <arg file="@{file}/>
      </java>
   </sequential>
</macrodef>

<parallel threadCount="4">
  <disturbed file="dr/one"/>
  <disturbed file="dr/two"/>
  <disturbed file="dr/three"/>
  <disturbed file="dr/four"/>
  <disturbed file="dr/five"/>
  <disturbed file="dr/six"/>
  <disturbed file="dr/seven"/>
  <disturbed file="dr/eight"/>
  <!-- repeated about 40 times -->
</parallel>			

The above example shows the use of parallel tags and the use of threadCount and threadsPerProcessor attributes. Running all those 40 tasks can put your system or server on a very very heavy load. But you can limit the concurrent process to limit the CPU, memory, I/O usage. This also a good example to show that how we can use threadcount in the ANT build file.


If you want to achieve parallelism without using any property then use this below code snippet. Put you task under <parallel> tags. Simple!!

<parallel>
    <task1>
    ....
    ....
    </task1>
    
    <task2>
    ....
    ....
    </task2>
</parallel>


Thank You

11 views

Recent Posts

See All