title: Eclipse long build time for java project
body: <p>EDIT: The solution was as follows: Disabling egit solved the building problem. For some reason, egit causes the build process to hang for many minutes.</p>
  
  <p>I have a problem when I need to rebuild my java project. Our project takes 12 minutes to compile with "clean project" in eclipse. It will hang very long on a somewhat random percentage. There should in theory be no buildling cycles, and I have set "Max iterations when building with cycles" to 1 just in case.
  I thought I had a nice solution to find out where it stopped: I wrote a small program to analyze the generated .class files too see which class-files it stops on for so long. So I wrote the attached program which sorts the generated .class -files by modifieddate
  Guess if I was surprised with the results!
  The build started around 12:20:40 and was finished 12:32:40
  The first of the 4458 class-files was generated 12:20:42, and the last was generated 12:21:22
  So the entire build took 40 seconds. So what the <em>beep</em> is eclipse doing those last 11 minutes??</p>
  
  <pre><code>import java.io.File;
  import java.util.*;
  
  public class AnalyzeBuildTime {
  
  public static void main(String[] args) throws Exception{
      File dir = new File(path_to_project);
      Vector&lt;File&gt; v = new Vector&lt;File&gt;();
      parse(v,dir);
      System.out.println("Nr of files: "+v.size());
      Collections.sort(v,new Comparator&lt;File&gt;() {
          public int compare(File o1, File o2) {
              return new Long(o1.lastModified()).compareTo(o2.lastModified());
          }           
      });
      System.out.println("Listing");
      for (File f : v) {
          System.out.println(f.getName()+"\t"+getTimeString(f.lastModified()));
      }
  }
  
  private static void parse(Vector&lt;File&gt; v, File f) throws Exception{
      if (f.isDirectory()) {
          for (File ff : f.listFiles()) {
              parse(v,ff);
          }
      }
      else if (f.getName().endsWith(".class")){
          v.addElement(f);
      }
  }
  
  public static String getTimeString(long l){
      Calendar c = Calendar.getInstance();
      c.setTimeInMillis(l);
      return zero(c.get(Calendar.HOUR_OF_DAY))+":"+zero(c.get(Calendar.MINUTE))+":"+zero(c.get(Calendar.SECOND)); 
  }
  
  private static String zero(int i) {
      if (i &lt; 10) return "0"+i;
      return ""+i;
  }
  }
  </code></pre>
  
  <p>EDIT
  Back from vacation, and have tried to understand this some more. I have now tried buildling my workspace via headless building ala:</p>
  
  <pre><code>eclipsec.exe -noSplash -application org.eclipse.jdt.apt.core.aptBuild -data c:\workspace
  </code></pre>
  
  <p>This seems to build fine for some time, displaying messages ala "(Found 4345 warnings) Compiling Diverse", then suddenly stops and hangs for about 4-5 minutes before continuing, continuing on "(Found 4346 warnings) Compiling Diverse" as if nothing has happened (and yes, it reaches a different warning count each time..)
  Have tried profiling it with jvisualvm, but really does not know what I should be looking for. Some "Compiler Processing Task" threads are spawned in sequence, and the last "Compiler Processing Task" thread seems to be in wait mode when it hangs, with 0ms in "Running", and when the compiling eventually continues, this thread is stopped and a new "Compiler Processing Task" thread starts.
  It should be noted that when compiling from command line, it compiles all my projects, and not only the big project that takes so much time from within eclipse, and it seems to be finished with the big 'Pos' project before it hangs on usually 'Diverse' or another project.
  I just tried upgrading from eclipse neon to eclipse oxygen, but it seems to have the same behaviour.</p>
  
  <p>EDIT2
  Well, I've finally found a "solution", but I'm not that happy with it.
  I'm using eclipse Neon (4.6.2), and have also tried switching to oxygen, but the problem persists.
  I then tried building my project on my old computer running eclipse mars (4.5.2), and strangely enough did not experiance any build hangs. So I have copied my mars-eclipse from my old computer, and Clean on my big project now takes 55 seconds, and clean all takes 1:15. Still very interested in the reasons for the build hangs, so that I can use newer versions of eclipse.</p>