You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

parallel.html 3.2 KiB

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