views:

64

answers:

2

I'm trying to optimize the startup time/class loading time of my Java web app because its on the Google App Engine and startup time is important.

Is there a way I can turn on some sort of class loading debug messages or someway to see where time is being spent while class loading? I want to see if any specific libraries take a while to load and then get rid of them if they aren't essential.

+4  A: 

If you want to see what classes were loaded and in what order you can run with the -verbose flag.

Example:

java -verbose:class <MyProgram>

Output:

[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
[Loaded java.lang.reflect.Type from shared objects file]
[Loaded java.lang.reflect.AnnotatedElement from shared objects file]
[Loaded java.lang.Class from shared objects file]
[Loaded java.lang.Cloneable from shared objects file]
[Loaded java.lang.ClassLoader from shared objects file]
[Loaded java.lang.System from shared objects file]
[Loaded java.lang.Throwable from shared objects file]
[Loaded java.lang.Error from shared objects file]
..
..
..
Amir Afghani
Unfortunately, this will not work within the App Engine environment where Spines is trying to debug this problem.
Peter Recore
I don't understand, why not?
Amir Afghani
Because he is deploying to App Engine. You don't have any control over the jvm in App Engine. once you upload your project, it is executed by the app engine runtime. you don't start the jvm yourself.
Peter Recore
I see, thanks for the explanation.
Amir Afghani
A: 

Adding a library to the classpath won't cause it to get loaded btw, not any class in one. Classes are typically loaded as needed (maybe the JVM will preload some common classes but that's usually as far as it goes). The only real need to reduce the number of classes/librarie is therefore reduction in maintenance (even if it's not used you're going to have to keep track of versions etc.) and possibly download times and deployment size.

Those can be important factors of course, but typically won't affect runtime performance. The main benefit of logging classloading is to detect whether maybe an incorrect version of a class is being loaded and from where if you're getting weird problems. For example you're expecting a class to be loaded from a library you've explicitly included but instead it's being loaded from a lib/ext directory where it was put by some unscrupulous 3rd party application (Adobe has a tendency to put things there, maybe others too, but it also can happen with applications running inside appservers getting common classes from the appserver at times which may conflict with different versions of those same classes distributed with the application).

jwenting