Is it possible to compile a large Java module in parallel?
Yes it is possible to build Java code in parallel.
The Java compiler (javac
) itself doesn't do this, but both Maven and Ant (and some versions of Make) can run multiple javac
instances in parallel.
Furthermore, the Eclipse Java compiler is multi-threaded and you can tell Maven to use it instead of javac
; see https://stackoverflow.com/a/3727542/139985
I note that your example involves compiling a single class with a huge number of methods. Parallel compiler instances won't help with that. The Eclipse compiler might help depending on how it is implemented.
However, I put it to you that that is an unrealistic example. People don't write code like that in real life1, and code generators can (and should) be written to not emit source code like that.
1 - Their co-workers will rebel ...
javac
runs always single-threaded. There is a case for improving javac performance JDK-4229449 : RFE: Please multithread javac for better performance however Oracle does not intend to change the compilation architecture.