如何在Ant中使用并行任务

时间:2021-11-18 13:48:37

Hello im working on application which is runing tests one by one trough Ant call. In .bat file build.xml is called in which is called another file with name of .class test which are called is there any chance to make this parallel in Ant?

你好我正在研究应用程序,它通过Ant调用逐个运行测试。在.bat文件中调用build.xml,在其中调用名为.class test的另一个文件,调用它是否有机会在Ant中进行此并行?

My ant config look like this:

我的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>

where patternset includes are test to run. And i want these test to run parallel. I think i will need something like foreach for all tests to be run in thread.

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

1 个解决方案

#1


2  

In Ant, Task can be executed in parallel using parallel tag. Following is an example extracted from official Apache Ant site:

在Ant中,Task可以使用并行标记并行执行。以下是从官方Apache Ant站点中提取的示例:

<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.

此示例表示使用threadCount和threadsPerProcessor属性的典型需求。旋转所有这40个任务可能会削弱系统的内存和CPU时间。通过限制并发执行的数量,您可以减少对CPU,内存和磁盘IO的争用,从而实际上更快地完成。这也是使用threadCount(以及可能的threadsPerProcessor)的一个很好的候选者,因为每个任务都是独立的(每个新的JVM都是分叉的),并且不依赖于其他任务。

Refer official Apache Ant site for more information.

有关更多信息,请参阅官方Apache Ant站点。

#1


2  

In Ant, Task can be executed in parallel using parallel tag. Following is an example extracted from official Apache Ant site:

在Ant中,Task可以使用并行标记并行执行。以下是从官方Apache Ant站点中提取的示例:

<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.

此示例表示使用threadCount和threadsPerProcessor属性的典型需求。旋转所有这40个任务可能会削弱系统的内存和CPU时间。通过限制并发执行的数量,您可以减少对CPU,内存和磁盘IO的争用,从而实际上更快地完成。这也是使用threadCount(以及可能的threadsPerProcessor)的一个很好的候选者,因为每个任务都是独立的(每个新的JVM都是分叉的),并且不依赖于其他任务。

Refer official Apache Ant site for more information.

有关更多信息,请参阅官方Apache Ant站点。