Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple cores/processors when compiling Java

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?

like image 755
Xavier Nodet Avatar asked Sep 16 '10 14:09

Xavier Nodet


People also ask

Does compiling use multiple cores?

And for 1000 files, each core of the processor can happily compile one file at a time, keeping all cores totally busy. Tip: "make" uses multiple cores if you give it the right command line option. Without that it will compile one file after the other on a 16 core system.

Does Java automatically use multiple cores?

Java will benefit from multiple cores, if the OS distribute threads over the available processors. JVM itself do not do anything special to get its threads scheduled evenly across multiple cores.

Is Java compiler single threaded?

javac runs always single-threaded.

Do you need multiple cores for multithreading?

Multithreading refers to a program that can take advantage of a multicore computer by running on more than one core at the same time.


1 Answers

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.

like image 176
Joachim Sauer Avatar answered Oct 05 '22 15:10

Joachim Sauer