cp30报错No operations allowed after connection closed

使用mysql+cp30连接池时,报错No operations allowed after connection closed。从报错信息来看,是connection断开导致的错误。在网上搜索后发现,较新版本的mysql配置了connection的默认时间,默认时间一般为8个小时。超过了八个小时,mysql则会自动断开connection,解决方法为:

在xml文件中增加property配置


        <!--最大空闲时间,1800秒内未使用则连接被丢弃 若为0则永不丢弃 默认值为0 --> 
        <property name="maxIdleTime" value="1800"/>
        <!--每300秒检查所有连接池中的空闲连接 默认值为0 0 --> 
        <property name="idleConnectionTestPeriod" value="300"/>
        <!-- 获取连接时测试有效性,每次都验证连接是否可用 -->
        <property name="testConnectionOnCheckout" value="true"/>

注意:idleConnectionTestPeriod的value要根据自己不同的需求设置不同的值

原创文章 12 获赞 51 访问量 5676

猜你喜欢

转载自blog.csdn.net/weixin_44582716/article/details/105802318