3

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.

Sun
  • 53
  • 1
  • 5

2 Answers2

1

The jars are in the classpath for a reason. They are probably added to you webapp through a build management system (maven, gradle, ...) - therefore there may be some dependencies to these jars.

Removing jars from the classpath will produce NoClassDefFoundError. I guess you have to live with that amount of jars unless some of them are not needed (which is not easy to find out).

Best check you dependency graph (maven and gradle have them) for possibly redundant, not needed or obsolete jars in your project. Also check for jars that come in different version like random-1.0.0.jar and random-1.0.1.jar and exclude one of them if possible.

Pang
  • 9,564
  • 146
  • 81
  • 122
mana
  • 6,347
  • 6
  • 50
  • 70
  • Thanks mana. Maven dependency plugin would have been of great help if project is maven based. Unfortunately this project is not maven based. – Sun Oct 03 '12 at 10:55
0

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.

Community
  • 1
  • 1
James Black
  • 41,583
  • 10
  • 86
  • 166
  • Thanks James. The links you shared were really useful specifically Oracle one as I already had looked into other SO link :). With those tools I was able to get initial dependency details. After that I had to fix runtime dependencies manually. Will accept your answer if there are no better solutions. Is there a way to free/unload classes from permgen which are less frequently used? [External jar classes] – Sun Oct 03 '12 at 10:57
  • You may want to follow the steps here: http://www.javabeat.net/2010/01/java-lang-outofmemoryerror-permgen-space/ – James Black Oct 03 '12 at 11:14