c3p0客户端超时,等待从com.mchange.v2.resourcepool.BasicResourcePool获取资源
问题描述:
我在tomcat版本7上部署了一个java应用程序。对于数据源,我使用了连接到mysql数据库的c3p0。 它工作正常多年,最近我开始得到这个错误: “客户端超时等待从com.mchange.v2.resourcepool.BasicResourcePool获取资源”。c3p0客户端超时,等待从com.mchange.v2.resourcepool.BasicResourcePool获取资源
当我遇到此问题时,唯一的解决方案是重新启动应用程序。重新启动mysql并没有帮助。
我也有PHP应用程序使用保存数据库,他们不受影响,他们正常工作。
我的Java应用程序只用于一个小团队,它是一个后端应用程序。
这里是我的C3P0配置:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/db?relaxAutoCommit=true&autoReconnect=true&autoReconnectForPools=true" />
<property name="user" value="viva4578" />
<property name="password" value="amd139fbg" />
<property name="initialPoolSize" value="5" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxConnectionAge" value="14400" />
<property name="checkoutTimeout" value="30000" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryAttempts" value="30" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="true" />
<property name="preferredTestQuery" value="SELECT 1" />
<property name="idleConnectionTestPeriod" value="3600" />
<property name="maxIdleTime" value="7200" />
<property name="maxIdleTimeExcessConnections" value="1800" />
<property name="unreturnedConnectionTimeout" value="3600" />
<property name="debugUnreturnedConnectionStackTraces" value="true" />
</bean>
这里是C3P0的输出日志启动应用程序后:
Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [
acquireIncrement -> 1,
acquireRetryAttempts -> 30,
acquireRetryDelay -> 1000,
autoCommitOnClose -> false,
userOverrides -> {},
automaticTestTable -> null,
breakAfterAcquireFailure -> false,
checkoutTimeout -> 30000,
connectionCustomizerClassName -> null,
connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester,
contextClassLoaderSource -> caller,
dataSourceName -> z8kflt9n1b12nsh118544e|7bc1a68b,
debugUnreturnedConnectionStackTraces -> true,
description -> null,
driverClass -> com.mysql.jdbc.Driver,
extensions -> {},
factoryClassLocation -> null,
forceIgnoreUnresolvedTransactions -> false,
forceUseNamedDriverClass -> false,
identityToken -> z8kflt9n1b12nsh118544e|7bc1a68b,
idleConnectionTestPeriod -> 3600,
initialPoolSize -> 5,
jdbcUrl -> jdbc:mysql://localhost:3306/db?relaxAutoCommit=true&autoReconnect=true&autoReconnectForPools=true,
maxAdministrativeTaskTime -> 0,
maxConnectionAge -> 14400,
maxIdleTime -> 7200,
maxIdleTimeExcessConnections -> 1800,
maxPoolSize -> 20,
maxStatements -> 0,
maxStatementsPerConnection -> 0,
minPoolSize -> 5,
numHelperThreads -> 3,
preferredTestQuery -> SELECT 1,
privilegeSpawnedThreads -> false,
properties -> {user=******, password=******},
propertyCycle -> 0,
statementCacheNumDeferredCloseThreads -> 0,
testConnectionOnCheckin -> true,
testConnectionOnCheckout -> true,
unreturnedConnectionTimeout -> 3600,
usesTraditionalReflectiveProxies -> false
]
我使用C3P0的版本0-0.9.5。
如果有人能帮助
谢谢
答
这里
<property name="checkoutTimeout" value="30000" />
已配置C3P0到抛出此异常,如果客户端无法获得在30秒内提供服务。这开始发生。据推测DataSource
的负载增加了。考虑扩展它。使maxPoolSize
变大,同时增加numHelperThreads
以防止问题在异步任务中积压。 (您也可以增加checkoutTimeout
的值,或删除设置,以便客户端结帐永不超时,这将消除此异常,但不是真的问题,30秒是等待连接的很长时间。调整c3p0以提供连接的速度可能会比这更快)
好,非常感谢您的意见。我的意见30秒是很多,除非有缓慢的查询。 – kchetoua
我换了一个log4j的配置,现在我看到这个异常 – kchetoua
签出的资源已过期,并且将被销毁:com.mchange.v2.c3p0.impl.NewPooledConnection 也许这就是问题的根本原因是什么? – kchetoua