I have a real head-scratcher here. I tried everything, searched everywhere. It comes from an application I inherited that test JARs.
(It consists of a GUI front and a command-line application that does the actual checking. The GUI runs the command-line app by launching a new JVM on itself [java -cp “itself.jar” com.different.mainClass]. It’s a bad design, I know, but may be relevant.)
Anyway, this program contains some reflection calls nested inside two for-loops. The problem is that when the application is JARed up, the first reflection call takes exactly one second every iteration. But when it runs from classes, it takes a few milliseconds.
Practically, this means this command:
java -jar myjar.jar
takes hours.
This command:
java -cp "...[bunch of jars];myjar.jar" com.myclasses.main
takes minutes.
The JAR being tested is always a jar. The difference is only in the test application.
Any ideas or avenues to pursue are greatly appreciated. Thank you!
You could consider running your program under a profiler like the Eclipse TPTP or YourKit and more precisely identify where your time is being spent. That will very likely point you to an error in your code, or somewhat less likely to point to a bug in a library. Then, if you cannot figure it out still, post the relevant code here and we can help out.