I am using jboss 4.2.3 with mysql-connector-5.1.8. My application is doing a large number of DB reads(order of few hundered thousands) and signification of writes. Over a period of time jboss crashes with OOM exceptions. When i checked heap dump i see a large number of
com.mysql.jdbc.StatementImpl$CancelTask
objects around 4 million taking hunderds of MB of data
Is it a memory leak ? what exactly is it used for and how to disable this?
Since i am using Container Managed transaction with ejb injected entity manager I figured there is not explicit close required. On digging further I found out that the query-transaction timeout was set to 30 mins with query timeout enabled.开发者_如何学C Looks like CancelTask
object lives until the timer expires. Once I reduce the transaction timeout those objects are cleaned up on timer expirations
I had asimilar problem on tomcat using the DB connection pooling with a MySql driver: There were loads of JDBCResultSet
and StatementImpl
objects in the heap which were not removed. After a long search I found out that setting the maxAge
parameter of the datasource in the tomcat context.xml file helped.
It's very hard to answer your question without seeing some code... still...
I get this hunch that you don't close your JDBC resources properly (connection / statements / Resultsets). These CancelTask objects are created when queries timeout as far as I know.
Turn on logging of abandoned connections in your datasource or connection pool. You might be missing out on closing some of the connections somewhere. If that is the case you can set remove abandoned as true, but this is not a replacement for properly closing your session and database connections after you are done with your querying.
精彩评论