~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to docs/manual/CoreTasks/parallel.html

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
 
 
3
<head>
 
4
<meta http-equiv="Content-Language" content="en-us">
 
5
<title>Ant User Manual</title>
 
6
</head>
 
7
 
 
8
<body>
 
9
 
 
10
<h2>Parallel</h2>
 
11
<h3>Description</h3>
 
12
<p>Parallel is a container task - it can contain other Ant tasks. Each nested
 
13
task within the parallel task will be executed in its own thread. </p>
 
14
 
 
15
<p>Parallel tasks have a number of uses in an Ant build file including:
 
16
<ul>
 
17
<li>Taking advantage of available processing resources to reduce build time</li>
 
18
<li>Testing servers, where the server can be run in one thread and the test
 
19
harness is run in another thread.</li>
 
20
</ul>
 
21
 
 
22
<p>Care must be taken when using multithreading to ensure the tasks within the
 
23
threads do not interact. For example, two javac compile tasks which write 
 
24
classes into the same destination directory may interact where one tries to
 
25
read a class for dependency information while the other task is writing the 
 
26
class file. Be sure to avoid these types of interactions within a 
 
27
&lt;parallel&gt; task</p>
 
28
  
 
29
<p>The parallel task has no attributes and does not support any nested 
 
30
elements apart from Ant tasks. Any valid Ant task may be embedded within a 
 
31
parallel task, including other parallel tasks.</p>
 
32
 
 
33
<p>Note that while the tasks within the parallel task are being run, the main 
 
34
thread will be blocked waiting for all the child threads to complete.</p>  
 
35
 
 
36
<p>If any of the tasks within the &lt;parallel&gt; task fails, the remaining 
 
37
tasks in other threads will continue to run until all threads have completed. 
 
38
In this situation, the parallel task will also fail.</p>
 
39
 
 
40
<p>The parallel task may be combined with the <a href="sequential.html">
 
41
sequential</a> task to define sequences of tasks to be executed on each thread
 
42
within the parallel block</p>
 
43
 
 
44
<h3>Examples</h3>
 
45
<pre>
 
46
&lt;parallel&gt;
 
47
  &lt;wlrun ...&gt;
 
48
  &lt;sequential&gt;
 
49
    &lt;sleep seconds=&quot;30&quot;/&gt;
 
50
    &lt;junit ...&gt;
 
51
    &lt;wlstop/&gt;
 
52
  &lt;/sequential&gt;
 
53
&lt;/parallel&gt;
 
54
</pre>
 
55
<p>This example represents a typical pattern for testing a server application. 
 
56
In one thread the server is started (the wlrun task). The other thread consists 
 
57
of a three tasks which are performed in sequence. The sleep task is used to 
 
58
give the server time to come up. Another task which is capable of validating 
 
59
that the server is available could be used in place of the sleep task. The 
 
60
test harness is then run. Once the tests are complete, the server is stopped 
 
61
(using wlstop in this example), allowing both threads to complete. The 
 
62
parallel task will also complete at this time and the build will then 
 
63
continue.</p>
 
64
 
 
65
<pre>
 
66
&lt;parallel&gt;
 
67
  &lt;javac ...&gt; &lt;!-- compiler servlet code --&gt;
 
68
  &lt;wljspc ...&gt; &lt;!-- precompile JSPs --&gt;
 
69
&lt;/parallel&gt;
 
70
</pre>
 
71
 
 
72
<p>This example shows two independent tasks being run to achieve better 
 
73
resource utilization during the build. In this instance, some servlets are being
 
74
compiled in one thead and a set of JSPs is being precompiled in another. As 
 
75
noted above, you need to be careful that the two tasks are independent, both in 
 
76
terms of their dependencies and in terms of their potential interactions in
 
77
Ant's external environment.</p>
 
78
<hr>
 
79
<p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
 
80
Reserved.</p>
 
81
</body>
 
82
</html>
 
83