gpt4 book ai didi

java - 如何在 Ant 中使用并行任务

转载 作者:行者123 更新时间:2023-11-30 02:29:37 24 4
gpt4 key购买 nike

您好,我正在开发通过 Ant 调用一一运行测试的应用程序。在 .bat 文件中调用 build.xml,其中调用另一个名为 .class test 的文件,该文件被调用是否有机会在 Ant 中进行并行处理?

我的 ant 配置如下所示:

<target name="testexec-run-pattern" description="=> run JUnit tests by Pattern">
<mkdir dir="${junit.dir}/xml" />
<input addproperty="input.pattern" />
<echo message="Executing pattern: ${input.pattern}" />
<junit showoutput="true" printsummary="on">
<classpath refid="classpath" />
<batchtest todir="${junit.dir}/xml">
<formatter type="xml" extension=".xml" usefile="true" />
<zipfileset src="${test.jar}">
<patternset includes="${input.pattern}" />
</zipfileset>
</batchtest>
</junit>
</target>

其中模式集包含要运行的测试。我希望这些测试并行运行。我想我需要像 foreach 这样的东西才能在线程中运行所有测试。

最佳答案

在Ant中,Task可以使用parallel标签并行执行。以下是摘自 official Apache Ant site 的示例:

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

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

This example represents a typical need for use of the threadCount and threadsPerProcessor attributes. Spinning up all 40 of those tasks could cripple the system for memory and CPU time. By limiting the number of concurrent executions you can reduce contention for CPU, memory and disk IO, and so actually finish faster. This is also a good candidate for use of threadCount (and possibly threadsPerProcessor) because each task is independent (every new JVM is forked) and has no dependencies on the other tasks.

引用official Apache Ant site了解更多信息。

关于java - 如何在 Ant 中使用并行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44567911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com