9

My application generates java code during runtime and compiles it using the JavaCompiler API. Some of the generated files can be rather large - up to a few hundred thousand lines. I find that when I run the javac command on the generated code in the command line, or alternatively if I use an application that does just the compilation via the JavaCompiler API, I can compile many of these files (~500), even if they are very large, in under two minutes. However, if I call the API via my application when it is running on a Tomcat server, the compilation time runs upwards of twelve minutes (!!!).

I would appreciate any suggestions on how to improve the performance of the compilation.

Thanks!

blockhead
  • 9,655
  • 3
  • 43
  • 69
Jewels
  • 966
  • 11
  • 28
  • I cannot place my finger on exactly why, but when I switched from using the default system compiler via a call to `ToolProvider.getSystemJavaCompiler();` but instead used Eclipse's JDT compiler, things sped up significantly. An explanation will happily be accepted as the answer. – Jewels Jun 30 '16 at 05:55
  • a guess would be eclipse has an incremental compiler so it isn't doing a clean build every time. This could be wrong though. Also doesn't answer the main question – Old Badman Grey Jun 30 '16 at 13:37
  • from looking at the jvm with jvisualvm it looks like javac runs the entire compilation in a single thread, while EclipseCompiler starts many many threads to compile the `.java` files. – Jewels Jan 25 '17 at 07:38

1 Answers1

1

Try to set the thread priority to the highest value (on the thread or thread pool):

setPriority(Thread.MAX_PRIORITY);
volatile
  • 179
  • 8