Why is my .jar file running slower than the program in eclipse?

I have a java program that reads a lot of input from a database, manipulates it, and then writes the data back to another database (using ODBC drivers, excel and access databases) on a new Windows 7 machine). The program takes about 17 minutes to run from eclipse, but when I created the .jar executable, it takes another 10 minutes to start (27 in total).

Two reasons that I have found so far for slow jar files (by searching for SO and google) are that they are compressed and that it takes a lot of time to write to the command line (or error log) than the console in eclipse. I tried to create an uncompressed jar file, and it accelerated by about 10 seconds (which could be completely random, since the startup time varies by about 30 seconds). I only have about 10 System.out.println() commands in the program, so this should not slow it down much.

Any ideas on what makes it work much slower, and if there is any way, can I speed it up again? Let me know if there are any other details that may matter that I should include. Thanks!

+6
source share
4 answers

Use JAMon . This is a monitoring library that will help you measure code execution time.

After you add some monitoring code to your methods, run it in Eclipse and as a JAR file and compare the results. This should allow you to narrow your search.

Also: check if your JAR file works with the same Java version as Eclipse (for example, Java 1.4.x can be much slower than 1.6.x).

+4
source

In my case, my application took 3 seconds to run on the eclipse, while it took 2 minutes when I launched it from jar.
My mistake was to select "Package required libraries into jar" when exporting my project to runnable jar.

I tried different ways to save time, but nothing helped except ..

If you have other maven dependencies or jar files in your project, you should use "**Extract required libraries into generated jar**" when exporting your project to a jar.

This solved my problem in a matter of seconds, and now both my eclipses and the jar file take the same time to start the application, 2 seconds.

Hope this helps new wrestlers.

Sincerely.

+2
source

I had a similar problem. The shell worked orders of magnitude slower, and it had nothing to do with the console output. I tried to set the JVM memory values, but that didn't make any difference.

The solution was to pack the ANT file with all the JAR files into an external folder using "Copy the necessary libraries to a subfolder next to the created JAR" in the "Runnable JAR File Export" wizard. Then start the main JAR using the command line -cp [YOURSUBFOLDER].

+2
source

You can check Java VM parameters (e.g. used GC, maximum memory, etc.). For data intensive applications, GC can slow down significantly.

+1
source

Source: https://habr.com/ru/post/917470/


All Articles