Using multiple cores/processors when compiling Java
As long as the javac you are calling doesn't use all the cores it doesn't really matter what you say in Ant. You can use the compiler
attribute to define which java compiler should be used for the task.
If you have several build targets you can use fork=yes
to execute the target(s) externally.
http://ant.apache.org/manual/Tasks/javac.html#compilervalues
I don't know of any way to do tell ant itself to make effective use of multiple cores. But you can tell ant to use the Eclipse Compiler, which has support for multithreaded compilation built-in.
You can use Buck Build to increase your build speed and utilize multiple cores.
In a nutshell:
Buck is a build system developed and used by Facebook. It encourages the creation of small, reusable modules consisting of code and resources, and supports a variety of languages on many platforms.
Buck builds independent artifacts in parallel to take advantage of multiple cores on your machine. Further, it reduces incremental build times by keeping track of unchanged modules so that the minimal set of modules is rebuilt.
The documentation seems to indicate that it's unlikely to work correctly with javac
.
Anyone trying to run large Ant task sequences in parallel, such as javadoc and javac at the same time, is implicitly taking on the task of identifying and fixing all concurrency bugs the tasks that they run.
Accordingly, while this task has uses, it should be considered an advanced task which should be used in certain batch-processing or testing situations, rather than an easy trick to speed up build times on a multiway CPU.