Section 7.4. Multithreading Tasks


7.4. Multithreading Tasks

The parallel task can contain other Ant tasks and execute each nested task in its own thread. While the tasks within the parallel task are being run, the main thread will be blocked waiting for all the child threads to complete.

This task is useful to speed up build-file processing and to launch external tasks that may depend on each other; you may want to launch a server and run tests on build output, for example. The attributes of this task appear in Table 7-5.

Table 7-5. The parallel task's attributes

Attribute

Description

Required

Default

failonany

Specifies you want the task to fail if any nested task fails.

No

 

pollInterval

Polls tasks; not implemented at this point.

No

1000

threadCount

Specifies the maximum numbers of threads you want to use.

No

 

tHReadsPerProcessor

Specifies the maximum number of threads you want to use for each processor. Requires JDK 1.4 or later.

No

 

timeout

Specifies a timeout, in miiliseconds, before the task fails.

No

 


Be careful when using this task as you would with any parallel task. For example, if you're compiling and two files have the same dependency, you could have file access conflicts.


The parallel task supports a daemons nested element, which is a list of tasks which are to be run in parallel daemon threads. The parallel task will not wait for these tasks to complete. Because they are daemon threads, however, they will not prevent Ant from completing the task.

The parallel task may be combined with the sequential task to define sequences of tasks to be executed on each thread inside the parallel task; for an example using parallel and sequential, see the next topic.



    Ant. The Definitive Guide
    Ant: The Definitive Guide, 2nd Edition
    ISBN: 0596006098
    EAN: 2147483647
    Year: 2003
    Pages: 115
    Authors: Steve Holzner

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net