The last packet successfully received from the server was XXX seconds ago

本文介绍如何使用Apache DBCP连接池提高应用性能,并避免数据库空闲超时问题。包括连接池参数设置及验证查询配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Database Connection Pools

Using a connection pool is recommended for improving the performance of your application, and to ensure that your application handles excessive concurrency without overloading your Shared Database configurations (which have a limited number of connections available to the application). CloudBees datasources use the Apache DBCP connection pool implementation, which has a wide set of connection options.  The configuration below is a good configuration for a lightly loaded application or an application running in the free app+db tier.

<resource name="jdbc/DATASOURCE_NAME" auth="Container" type="javax.sql.DataSource">
<param name="username" value="USERNAME" />
<param name="password" value="PASSWORD" />
<param name="url" value="JDBC_URL" />

<!-- Connection Pool settings -->
<param name="maxActive" value="5" />
<param name="maxIdle" value="2" />
<param name="maxWait" value="10000" />
<param name="removeAbandoned" value="true" />
<param name="removeAbandonedTimeout" value="60" />
<param name="logAbandoned" value="true" />
</resource>

Avoiding Database Idle Timeouts

MySQL includes a timeout that will close connections that have been idle for long periods of time. For improved Database performance, CloudBees DataSources use the Apache DBCP connection pool to reuse JDBC connections after they are closed by the application. If you use a connection that has been in the pool idle for too long, your application will likely experience the following error: "The last packet successfully received from the server was XXX seconds ago". The connection pool includes a setting the will validate and throw out dead connections when calling javax.sql.DataSource.getConnection(). To use this setting, add the following XML params to your DataSource definition in cloudbees-web.xml.

<param name="validationQuery" value="SELECT 1" />
<param name="testOnBorrow" value="true" />
http://wiki.cloudbees.com/bin/view/RUN/DatabaseGuide

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值