Search code examples
javatomcatprofilingclassloader

Too many classes loaded when application is deployed on tomcat


We are having a web application which depends on around 125 jars including spring, hibernet, zk, etc.

When we start the tomcat server, it loads around 55K classes into the permgen. Coz of this huge class loading, application startup takes significant amount of time. Moreover permgen space required by application is very high as other classes are also loaded during the program execution.

  • Is there a way to control how many classes are loaded at start up so that application comes up fast?
  • Is there a way to free/unload classes from permgen which are less frequently used? [These questions are specific to the classes which are loaded from the external jars]

I had tried with -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled options specified for java. But only 42 classes were unloaded after sometime.

Any help or pointers are highly appreciated.


Solution

  • You may want to use a tool to remove unneeded classes.

    This question dealt with this very issue:

    Tool to remove unnecessary dependencies in a Java project

    But this question on Oracle may be more useful:

    https://forums.oracle.com/forums/thread.jspa?threadID=1311910

    I think that GenJar2 (http://code.google.com/p/genjar2/) may best meet your needs though.