简体   繁体   English

JDBC CommunicationsException与MySQL数据库

[英]JDBC CommunicationsException with MySQL Database

I'm having a little trouble with my MySQL- Connection- Pooling. 我的MySQL连接池有一点麻烦。 This is the case: 就是这种情况:

Different jobs are scheduled via Quartz. 通过Quartz安排了不同的作业。 All jobs connect to different databases which works fine the whole day while the nightly scheduled jobs fail with a CommunicationsException... 所有作业都连接到不同的数据库,这全天都能正常工作,而夜间计划的作业因CommunicationsException而失败...

Quartz-Jobs: 石英作业:

Job1 runs 0 0 6,10,14,18 * * ?
Job2 runs 0 30 10,18 * * ?
Job3 runs 0 0 5 * * ?

As you can see the last job runs at 18 taking about 1 hour to run. 如您所见,最后一个作业在18点运行,大约需要1个小时才能运行。 The first job at 5am is the one that fails. 凌晨5点的第一项工作失败了。 I already tried all kinds of parameter-combinations in my resource config this is the one I am running right now: 我已经在资源配置中尝试了各种参数组合,这是我现在正在运行的参数组合:

<!-- Database 1 (MySQL) -->
<Resource
 auth="Container"
 driverClassName="com.mysql.jdbc.Driver"
 maxActive="100"
 maxIdle="30"
 maxWait="10000"
 removeAbandoned="true"
 removeAbandonedTimeout="60"
 logAbandoned="true"
 type="javax.sql.DataSource"
 name="jdbc/appDbProd"
 username="****"
 password="****"
 url="jdbc:mysql://127.0.0.1:3306/appDbProd?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"
 testWhileIdle="true"
 testOnBorrow="true"
 testOnReturn="true"
 validationQuery="SELECT 1"
 timeBetweenEvictionRunsMillis="1800000"
/>

<!-- Database 2 (MySQL) -->
<Resource
 auth="Container"
 driverClassName="com.mysql.jdbc.Driver"
 maxActive="100"
 maxIdle="30"
 maxWait="10000"
 removeAbandoned="true"
 removeAbandonedTimeout="60"
 logAbandoned="true"
 type="javax.sql.DataSource"
 name="jdbc/prodDbCopy"
 username="****"
 password="****"
 url="jdbc:mysql://127.0.0.1:3306/prodDbCopy?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"
 testWhileIdle="true"
 testOnBorrow="true"
 testOnReturn="true"
 validationQuery="SELECT 1"
 timeBetweenEvictionRunsMillis="1800000"
/>
<!-- Database 3 (MSSQL)-->
<Resource
 auth="Container"
 driverClassName="net.sourceforge.jtds.jdbc.Driver"
 maxActive="30"
 maxIdle="30"
 maxWait="100"
 removeAbandoned="true"
 removeAbandonedTimeout="60"
 logAbandoned="true"
 name="jdbc/catalogDb"
 username="****"
 password="****"
 type="javax.sql.DataSource"
 url="jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=catalog;useNdTLMv2=false"
 testWhileIdle="true"
 testOnBorrow="true"
 testOnReturn="true"
 validationQuery="SELECT 1"
 timeBetweenEvictionRunsMillis="1800000"
/>

For obvious reasons I changed IPs, Usernames and Passwords but they can be assumed to be correct, seeing that the application runs successfully the whole day. 出于明显的原因,我更改了IP,用户名和密码,但是可以看到它们确实是正确的,因为该应用程序整天都可以成功运行。

The most annoying thing is: The first job that runs first queries Database2 successfully but fails to query Database1 for some reason (CommunicationsException): 最烦人的事情是:运行第一个作业的第一个作业成功查询了Database2,但是由于某种原因而无法查询Database1(CommunicationsException):

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 39,376,539 milliseconds ago. 引起原因:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:从服务器成功收到的最后一个数据包是39,376,539毫秒之前。 The last packet sent successfully to the server was 39,376,539 milliseconds ago. 成功发送到服务器的最后一个数据包是39,376,539毫秒之前。 is longer than the server configured value of 'wait_timeout'. 大于服务器配置的“ wait_timeout”值。 You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 您应考虑在应用程序中使用连接之前使连接有效性到期和/或对其进行测试,或者增加服务器为客户端超时配置的值,或者使用Connector / J连接属性'autoReconnect = true'来避免此问题。

Any ideas? 有任何想法吗? Thanks! 谢谢!

如前所述,在连接池上启用连接验证。

I get this error when a connection is left idle for a while. 当连接闲置一会儿时出现此错误。 Do your jobs stop hitting the DB at some point, then run some queries? 您的工作是否会在某个时候停止访问数据库,然后运行一些查询?

It also happens when there's a link failure, you might want to check with your network team if the connection doesn't drop. 当链接失败时,也会发生这种情况,您可能需要与网络团队联系,以确认连接是否断开。

I have run into a similar issue using Oracle, and JDBC. 我在使用Oracle和JDBC时遇到了类似的问题。 It ended up I was consuming all of the connections that were available to the database, and I wasn't relinquishing any of them and my code would just halt or timeout. 最终,我消耗了数据库可用的所有连接,并且我没有放弃任何连接,并且我的代码只会暂停或超时。 Take a look at how you are handling your connections in your code. 看一下您如何处理代码中的连接。

暂无
暂无

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

相关问题 Android MySql:JDBC CommunicationsException - Android MySql : JDBC CommunicationsException com.mysql.jdbc.exceptions.jdbc4.CommunicationsException使用JDBC访问远程MySQL数据库时 - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException when using JDBC to access remote MySQL database CommunicationsException:连接到MySQL数据库 - CommunicationsException: Connecting to a MySQL database com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: “com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败”到远程数据库 - “com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure” to remote database AWS RDS连接数据库错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - AWS RDS connection database error : com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MySQL + Apache Tomcat 7 - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MySQL + Apache Tomcat 7 第一次尝试设置测试数据库但得到com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - First time trying to setup a test database but gets com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败? - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure? 引起原因:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException - Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM