How can I get the number of available processors in Ant

I would like to get the number of available processors using Ant build script (i.e. the value returned from Runtime.getRuntime (). AvailableProcessors (). Is there an existing property that contains this value, or should I write an Ant custom task?

+3
source share
4 answers

write your own ant task , just how to write a class

+2
source

This post by Ilya Chemodanov explains the two solutions beautifully.

If you do not want to compile and import the Java class, you can do it in pure ant: (although these are pretty hacks)

<target name="get-cores">
    <property environment="env"/>
    <!-- support for Windows -->
    <condition property="cores.count" value="${env.NUMBER_OF_PROCESSORS}">
        <os family="windows" />
    </condition>
    <!-- support for Linux and Solaris (package SUNWgnu-coreutils is required) -->
    <exec executable="nproc" outputproperty="cores.count" os="Linux,SunOS,Solaris">
        <arg value="--all"/>
    </exec>
    <!-- support for Mac OS X -->
    <exec executable="sysctl" outputproperty="cores.count" os="Mac OS X">
        <arg value="-n"/>
        <arg value="hw.ncpu"/>
    </exec>
    <echo message="Number of cores: ${cores.count}"/>
</target>
+3

JVM ant. :

  • Java, . java- outputproperty, , ant.
  • , exec - , . , outputproperty , ant.
0

, , .

-1

Source: https://habr.com/ru/post/1713319/


All Articles