title: Is it possible to compile a large Java module in parallel?
body: <p>I know that multiple modules can be compiled using multiple threads where each thread compiles a single module but what if I have a single large module? Does Javac or the Eclipse Java Compiler support compiling single modules in parallel (using many threads)? Or is there any other Java compiler which supports it?</p>
  <p><strong>Update</strong>: I created a Java source file with ~50k simple methods (just for the purpose of this test) such as:</p>
  <pre class="lang-java prettyprint-override"><code>    static int add1(int a, int b, int c) {
          return 2 * a + 55 * b - c;
      }
  
     static int add2(int a, int b, int c) {
          return 2 * a + 55 * b - c;
      }
  
     static int add3(int a, int b, int c) {
          return 2 * a + 55 * b - c;
      }
  
  </code></pre>
  <p>These methods do not depend on each other so compilation could be done in parallel (at least in theory). Compiling this file with <code>Javac</code> on my 12 core + HT machine lead to an average 20% CPU usage with a really short spike of up to 50%. This leads me to believe that although there is some parralelization done inside <code>Javac</code>, it is really minor.</p>
  <p>The <strong>interesting</strong> thing is that if I create 2, 3 or 4 classes with the same number of methods and compile them at the same time with a single <code>Javac</code> process, I cannot get a higher CPU usage. The compilation takes exactly 2x, 3x, 4x longer which shows that Javac doesn't compile these totally unrelated classes in parallel. But if I start separate Javac processes to compile these files separately, the CPU jumps to almost 100% when 4 files(=<code>Javac</code> processes) are used and the compilation time is just 5-10% higher than compiling a single file (compared to this, a single <code>Javac</code> process compiling all these 4 files, the compilation takes 400% longer).</p>
  <p>So my opinion is that <code>Javac</code> does compile files using multiple threads but it is kind of limited to ~4 threads, it cannot fully utilize a 12 cores machine. Also to me it seems that <code>Javac</code> compiles <strong>multiple</strong> files in serial, it only uses cores/threads to compile a single file in parallel(I believe that when a single file is compiled, some parts can be done in parallel and this is what Javac does, <strong>but what about compiling multiple files in parallel?</strong> If I have 100 files which are independent I should be able to see my CPU jump to 100% which is not the case.)</p>