views:

206

answers:

4

I use a desktop with eight cores to build a Java application using Ant (through a javac target). Is there a way to speed up the compilation by using more than one thread or process?

I know I can run several Ant tasks in parallel, but I don't think this can be applied to a single compilation target, or does it?

+5  A: 

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.

Joachim Sauer
A: 

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.

bosmacs
A: 

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

Matti
+1. I just want to add that currently `javac` is single-threaded ( http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6629150 ) and it is not a trivial task to make it multi-threaded ( http://blogs.sun.com/jjg/entry/towards_a_multi_threaded_javac ).
Giuseppe Cardone
A: 

Not as far as I know. The Eclipse compiler has some work done to speed up using multiple cores but it does not buy as much as you probably would like it to.

Question is, can you live with incremental compilation for development, and only recompile those that changed? The full rebuild can then be left to the build server.

Thorbjørn Ravn Andersen