WebApp (Tomcat-jdbc) Pooled DB connection throwing abandon exception

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 19:07:32

Even though I'm over 1 year late at coming by this page, yet I stumbled here cos I was experiencing similar problems and in need of a solution too. So I thought i'd share what eventually worked for me.

In my case, after finding and reading through this article >>> configuring-jdbc-pool-high-concurrency - I just added an interceptor like this to my pool configuration;

"org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"

so that the line (from your posted code above) where you do setJdbcInterceptors(...) should now look like the following;

p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
            + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;"
            + "org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer");

Explanation - Quoting from the article, it says;

We want to make sure that when we detect that the connection is still being used, we reset the timeout timer, so that the connection wont be considered abandoned. We do this by inserting an interceptor.

Each time a statement is prepared or a query is executed, the timer will reset the abandon timer on the connection pool. This way... doing lots of queries and updates, will not timeout.

Bearing in mind you most likely have overcome the issue a long time ago, I still hope this helps anybody else having similar issues that bumps into this page, just like I did.

Cheers!

Have you seen the information on the Tomcat website relating to PoolConnection. Perhaps what you need is to look at the property minEvictableIdleTimeMillis

To answer your question you are timing out because you are checking for idle & abandon connections every 30 seconds (see TimeBetweenEvictionRunsMillis) and since you are setting an evictable idle timeout at 30 seconds (see minEvictableIdleTimeMillis) then you end up with what you have. You have said that you are receiving this exception while idle, I suspect the exception is a result of closing idle connection as opposed to abandoning a connection. From my understanding abandoning a connection is used for timing out longer than expected queries (as opposed to idle connections).

Personally I would not want to have connections alive forever because they would be consuming resources (that is a connection to the db) unnecessarily. I would play around with my max connections, eviction runs and idle times to optimise for my own requirements. I guess you can set these values large enough to almost be forever! It does really depend on what you are doing though...

Sorry I couldn't be much more help here.

Patrikoko

Just add below entry in tomcat7 conf/server.xml or in context.xml wherever your resource tag is present.

jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;
org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"

track 'removeAbandonedTimeout' in the configuration file. this should be max running query in the application. othewise it will close connection in the middle of execution

rajesh chaganti

If you define your datasource in the context.xml of tomcat then you should add the ResetAbandonedTimer like below :

jdbcInterceptors="ConnectionState;StatementFinalizer;ResetAbandonedTimer"

After setting ResetAbandonedTimer, issue got resolved in my application, Requesting you to let me know is there any relation between ResetAbandonedTimer interceptor and removeAbandoned="true" removeAbandonedTimeout="60"

The answers to this question were very helpful to me.

Though in my case, I already had the "ResetAbandonedTimer" JDBC Interceptor configured.

However, I had a query that ran for longer than the "removeAbandonedTimeout" that I had also configured. Once I increased the "removeAbandonedTimeout" the problem went away.

Had a similar problem ie., tomcat was closing JDBC connection due to it becoming abandoned because a transaction was taking a long time.

Resolved it by realizing that abandoned and idle are different and by setting: spring.datasource.tomcat.removeAbandonedTimeout: 86400 #seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!