Fixing issue with Classloader leaks.

We had an issue with a classloader leak. There were three things we had to do before it worked.

  1. Made the mysql connector provided and add mysql-connector jar to the tomcat/libexe/lib directory
    1. Maven block:
      <scope>provided test</scope>
  2. Added the following jvm option to use G1 garbage collection, and enable class unloading and perm gen sweep.
    NOTE: You need all three for this to work. Ignore the warning from java: “Please use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future.” I’ve tried just G1, G1 with class unload, and G1 with perm gen. They are all needed for heap to stay low and for classes to be unloaded.

    -XX:+UseG1GC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
  3. Added the following library for classloader leak prevention.
    1. Add the following block in your pom.xml of the web module:
    2. Add the following listener to your web.xml:

Once that is all setup, do a clean package on maven, redeploy and restart tomcat


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s