Too many instances of “com.mysql.jdbc.JDBC4Connect

2019-06-06 08:53发布

问题:

Used memory of the server has been increasing. I suspect a memory leak here. And when I had a look on the heap dump, I see too many instances of "com.mysql.jdbc.JDBC4Connection" loaded in the memory. Wherever I am using the connection, I am closing the connection, resultset and prepared statement. Am I doing something wrong ?

5,576 instances of "com.mysql.jdbc.JDBC4Connection", loaded by "sun.misc.Launcher$AppClassLoader @ 0x68001f718" occupy 165,513,640 (55.60%) bytes. 
Keywords
com.mysql.jdbc.JDBC4Connection
sun.misc.Launcher$AppClassLoader @ 0x68001f718

回答1:

I am sure you didn't close the connection some where. Please carefully review your code again. However, if you fail to resolve the problem, try to use a connection pooling mechanism like this: https://devcenter.heroku.com/articles/database-connection-pooling-with-java