The latest versions of tomcat, 8.5.11 (8.xx) behave differently with respect to the JDBC/DB configuration. Earlier (at least until the 7.xx versions), it used bail out quickly if the MySQL connection failed but now, it tries 3 times and then bails out. This adds an average of about 20 secs delay before the server gives up on the DB connection and responds to the client. I have checked the JDBC configuration parameters, but there is nothing that seems to reduce this delay. Any thought on this is appreciated.
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxTotal="1000" maxIdle="30" maxWaitMillis="100"
name="jdbc/mydb" password="mypass" type="javax.sql.DataSource" username="myname"
url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true&characterEncoding=UTF-8"/>
As per the details that you've provided, I don't completely agree with what you say. It is not Tomcat 8 trying to reconnect to your MySQL database, but it is a parameter on your MySQL JDBC URL (Connection String) that suggests to do this. autoReconnect=true
This MySQL documentation provides you more information about such behaviors when used. If you scroll down to the section that talks about autoReconnect
- firstly is not suggested until it is very necessary to do so. And if autoReconnect is enabled, the initial time to wait between re-connect attempts (in seconds, defaults to '2'). This is defined by the parameter initialTimeout
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.