先看看官方文档中jdbc的几个Timeout

loginTimeout (int)
Specify how long to wait for establishment of a database connection. The timeout is specified in seconds.
指定等待数据库建立连接的超时时间,单位是秒

connectTimeout (int)
The timeout value used for socket connect operations. If connecting to the server takes longer than this value, the connection is broken. The timeout is specified in seconds and a value of zero means that it is disabled.
指定Socket做connect时的超时时间,单位是秒

socketTimeout (int)
The timeout value used for socket read operations. If reading from the server takes longer than this value, the connection is closed. This can be used as both a brute force global query timeout and a method of detecting network problems. The timeout is specified in seconds and a value of zero means that it is disabled.
指定底层socket receive的超时时间,单位是秒,值可以为任意正整数,“0”表示没有超时,一直等,直到返回

cancelSignalTimeout (int)
Cancel command is sent out of band over its own connection, so cancel message can itself get stuck. This property controls “connect timeout” and “socket timeout” used for cancel commands. The timeout is specified in seconds. Default value is 10 seconds.
指定发送取消命令的超时时间,单位是秒

socketTimeout

最近测试过程中遇到一个现象,集群的同步备库宕机后,数据库有一段时间连接数被撑满了
分析后,跟socketTimeout配置有关
1、同步备机宕机后,集群有同步转异步的逻辑,假定耗时20s
2、因为socketTimeout设置了10s,超时后应用发起后续请求,直至连接数被撑满,会导致服务器可用的woker线程变少,严重则会导致期间服务不可用。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐