我得到這個異常只適用於運行幾天後我的代碼中的一些數據庫更新。一些請求通過,其中一些(相同的java代碼)失敗。MaxOpenPreparedStatements達到的限制
java.sql.SQLException: MaxOpenPreparedStatements limit reached
at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:109)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
at com.prog.C.f(C.java:967)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.util.NoSuchElementException
at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:808)
at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:107)
... 15 more
數據源配置:
<bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" lazy-init="true" scope="singleton">
<property name="driverClassName" value="${jdbc.driver.class}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxOpenPreparedStatements" value="20"/>
</bean>
有百達可用的連接。我該如何解決它?謝謝。