1

I've googled and search stackoverflow, a lot but can't find the answer for this.

I have a Maven, Spring MVC Web app, connecting to a MySQL database.
The problem is that every time I redeploy (stop, undeploy then deploy) my war file I get the following exceptions in the log file:

SEVERE: The web application [/XYZ-0.0.0] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
SEVERE: The web application [/XYZ-0.0.0] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

After +-5 redeploys I get java.lang.OutOfMemoryError: PermGen space error and have to restart Tomcat - sometimes I have to reboot my machine.

I've looked at: To prevent a memory leak, the JDBC Driver has been forcibly unregistered and tried option 3 (Not sure how or what to move to Tomcat's /lib directory, i.e., do I 'move' spring-jdbc or mysql-connector-java?)

I've implemented a connection pool in an attempt to fix the problem, but it didn't help.

I use Netbeans but I've installed the 'windows version' of Tomcat 7, i.e., the one without the catalina.bat file and thus I can't get the profiler up and running. (I would like to not re-install Tomcat...)

Please help - How do I find and fix the memory leak?

Community
  • 1
  • 1
TungstenX
  • 830
  • 3
  • 19
  • 40
  • You'll need to add `classesToInitialize="com.mysql.jdbc.NonRegisteringDriver"` to your Listener declaration inside server.xml. Please take a look at http://stackoverflow.com/questions/24850091/the-web-application-registered-the-jdbc-driver-com-mysql-jdbc-driver-but-fa/24850221#24850221 – ksokol Mar 31 '15 at 16:53
  • Thank you ksokol, I've tried it (move mysql-connector-java-5.1.30.jar to Tomcat 7.0\lib\ and in my pom I marked it as `provided` and edited the server.xml file) but Tomcat still warns of a memory leak when I deploy, use the webapp, stop and undeploy. – TungstenX Apr 01 '15 at 07:46
  • I have notice that the memory "goes away" after a few minutes, i.e. if I click on `Find leaks` and found a leak, then wait for a few minutes and click it again there are no leaks... – TungstenX Apr 07 '15 at 10:02

1 Answers1

0

You could manually unload all JDBC drivers within the contextDestroyed method of a ServletContextlistener. You can find example code here:To prevent a memory leak, the JDBC Driver has been forcibly unregistered

You should also consider to place the JDBC driver into the TOMCAT_HOME/lib folder instead of providing it within your WAR so the driver is just loaded once instead of once on each redeployment and once for each web application.

The message you get after you clicked on the "find leaks" button in Tomcat manager is a bit misleading. This message just indicates that there are some classes from a previous deployed instance still loaded and the garbage collector has not yet unloaded them but may unload them later.

I recently answered a similar question and explained there how to find memory leaks in a web application related to tomcat: Tomcat memory Leak

Community
  • 1
  • 1
eztam
  • 3,443
  • 7
  • 36
  • 54