简体   繁体   English

Tomcat Jdbc连接池活动连接

[英]Tomcat Jdbc Connection Pool active connection

We have a spring-boot application which uses embedded tomcat for deployment and default tomcat-jdbc connection pooling with MySQL back-end with no customization for MySQL or Tomcat side. 我们有一个spring-boot应用程序,该应用程序使用嵌入式tomcat进行部署,并使用默认的 tomcat-jdbc连接池和MySQL后端,而没有为MySQL或Tomcat端进行自定义。
The app has a few schedulers that runs mostly during specific time in a day ie between the last cron run yesterday and 1st cron runs today, there is more than 9 hrs of gap. 该应用程序具有一些调度程序,这些调度程序主要在一天中的特定时间运行,即在昨天的最后一个cron运行到今天的第一个cron运行之间,存在9个小时以上的间隔。 However, whenever the cron ran earlier, it has never come across idle connection issue. 但是,只要cron运行得更早,它就永远不会遇到空闲连接问题。

Nowadays we see an error message 如今,我们看到一条错误消息
The last packet successfully received from the server was XXXXXXXX milliseconds ago. The last packet sent successfully to the server was XXXXXXXY milliseconds ago.

I can always try using testOnBorrow with validateQuery adn/or testWhileIdle etc as reqd to get this working but... 我总是可以尝试将testOnBorrowvalidateQuery adn /或testWhileIdle等作为reqd使用,以使其正常工作,但是...

I'm trying to understand the lifecycle of the active connection in tomcat-jdbc connection pooling. 我试图了解tomcat-jdbc连接池中活动连接生命周期 Acc to the documentation, the default value for wait_timeout for MySQL is 8 hrs , whereas default for idle_connection_timeout on Tomcat_jdbc is nearly 6 secs . 根据文档,MySQL的wait_timeout的默认值为8 hrs ,而idle_connection_timeout上的idle_connection_timeout的默认值为近6 secs

  1. If the default value is in use everywhere, then why issue has never surfaced before? 如果默认值在所有地方都在使用,那么为什么以前从未出现过此问题?
  2. Or is it something that the connections in the tomcat-jdbc connection pool are made active every time the cron starts running and becomes idle thereafter? 还是每次cron开始运行并随后变为空闲状态时,tomcat-jdbc连接池中的连接都处于活动状态?
  3. Is it the state of the spring-boot app or the scheduler that makes any difference? 弹簧启动应用程序或调度程序的状态有什么不同吗?

The problem is not in configuration or setup. 问题不在配置或设置中。 spring-boot app uses spring-data lib which makes use of the underlying connection pool . spring-boot应用程序使用spring-data lib,它利用了基础connection pool The pool handles the connection(s) as per the connection pool implementation. 池根据连接池的实现处理连接。 The use of @Transactional however decides when the underlying connection is opened. 但是,使用@Transactional决定何时打开基础连接。 If there is none specified in spring-boot app the default implementation of spring-data opens it during crud operations; 如果spring-boot应用程序中未指定任何内容,则默认的spring-data实现会在crud操作期间将其打开; else it is opened during the method call in application annotated with @Transactional . 否则,它将在应用程序中用@Transactional注释的方法调用期间打开。

In my case it was the latter.. After opening the connection a time taking non DB process was running which was making the connection to go idle after opening and was throwing exception while actually using it later. 在我的情况下是后者。.打开连接后,运行了一个耗时的非DB进程,这使连接在打开后变为空闲状态,并在以后实际使用它时引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM