Using multiple cores/processors when compiling Java

前端 未结 6 630
梦如初夏
梦如初夏 2020-12-13 19:30

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

6条回答
  •  臣服心动
    2020-12-13 19:34

    I assume that it might not help much because javac can pull all files in memory and if it has to do this with multiple processes it's just doubling the effort. However if you want to compile two fairly separate pieces of Java code, then you can just do:

    #!/usr/bin/env bash
    
    javac file1.java &
    javac file2.java &
    javac file3.java &
    
    wait;
    

    if the 3 files have mostly different dependencies, then it might save time, if the dependencies overlap, then it probably doesn't save much time.

提交回复
热议问题