MaxOpenPreparedStatements limit reached
I get this exception only for SOME database update in my code after several days of application running. Some of the requests passed, and some of them (the same java code) fail.
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
Datasource config:
<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"/>
开发者_C百科 <property name="maxOpenPreparedStatements" value="20"/>
</bean>
There are allways available connections. How can I fix it? Thanks.
This means you probably aren't closing resources properly. You should be doing it in a finally block within the scope of the method that you create them in.
You surely have prepared statements that are not being closed properly. A memory dump should help you find those.
Please try below in your configuration file :
db.pool.statements.enable=false
you can set negative value. Setting negative value creates unlimited open prepared statements in cache.
精彩评论