开发者社区> 问答> 正文

经常报错:Communications link failure The las?报错

@wenshao 你好,想跟你请教个问题:我正在使用druid-1.0.11.jar。经常报错:Communications link failure The last packet successfully received from the server was 0 milliseconds ago

<p style="font-size:13.3333px;">
	<span style="font-size:13.3333px;line-height:1.5;">请问我该如何配置,目前我的配置如下:</span>
</p>
<p style="font-size:13.3333px;">
	<!-- 数据源配置, 使用 Druid 数据库连接池 --><br>

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 
   <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
   <property name="driverClassName" value="com.mysql.jdbc.Driver" />
   
<!-- 基本属性 url、user、password -->
<property name="url" value="jdbc:mysql://localhost:3306/hs3?createDatabaseIfNotExist=true&autoReconnect=true&useUnicode=true&characterEncoding=utf8" />
<property name="username" value="root" />
<property name="password" value="root" />

<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="100" />
<property name="minIdle" value="100" /> 
<property name="maxActive" value="2000" />

<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 配置maxWait后 会使用公平锁,并发性能降下,可配置useUnfairLock=true,是否非公平锁 -->
<!-- <property name="useUnfairLock" value="true"/> -->

<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />

<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />

<property name="validationQuery" value="SELECT 1 FROM DUAL" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />

<!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> -->

<!-- 配置监控统计拦截的filters -->
   <property name="filters" value="stat" />
</bean>

展开
收起
爱吃鱼的程序员 2020-06-09 11:00:20 1463 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    mysql服务器配置wait_timeout=28800

    配置testWhileIdle=true,并且升级到最新版本就好了

    https://github.com/alibaba/druid/releases/tag/1.0.25

    我也更新了,也不行按照你说的做了,还是不可以,已经升级到1.0.25版本了,也已经配置配置testWhileIdle=true,数据库wait_timeout=100<divclass='ref'>

    引用来自“wenshao”的评论

    配置testWhileIdle=true,并且升级到最新版本就好了

    https://github.com/alibaba/druid/releases/tag/1.0.25

    问题解决了吗?我也遇到求解决

    <aclass="referer"target="_blank">@wenshao问题解决了吗,1.0.29也会出这个问题。

    <propertyname="validationQuery"value="SELECT1FROMDUAL"/> 这个配置独对。另外缺省mysql连接会最大存活7个小时,你在服务端做了什么额外操作么?

    在数据源端url配置这个:jdbc:mysql://locahost:3306/test?autoReconnect=true

    然后在数据源属性里面:<propertyname="testOnBorrow"value="true"/> 

    com.alibaba.druid.pool.DruidDataSourcehandleConnectionExceptiondiscardconnection
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communicationslinkfailure

    <atarget="_blank"rel="nofollow"><aclass="referer"target="_blank">@wenshao 同求问题解决方案

    时间没有超时啊,断开很奇怪

    有解决吗,碰到同样的问题。

    <atarget='_blank'>@蜗牛IT回复<aclass="referer"target="_blank">@蜗牛IT:谢谢,你的回答回复<aclass="referer"target="_blank">@刘王林123:这个问题最后不了了之解决了吗?碰到同样的问题

    2020-06-09 11:00:36
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
KR^X- Comprehensive- Kernel-Protection-Against-Just-In-Time-Code-Reuse 立即下载
Building a Real-Time Fraud Prevention Engine Using Open Source (Big Data) Software 立即下载
Scaling Spark applications by connecting code to resource consumption 立即下载