我已经在java
服务器上部署了应用程序。wildfly-15.0.1.FINAl
我正在使用OJDBC 12.1.0.2.0
驱动程序。
<datasource jndi-name="java:/DS_APP" pool-name="APP" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:@localhost:1521:MYDB</connection-url>
<driver>OracleJDBCDriver</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>3</min-pool-size>
<max-pool-size>200</max-pool-size>
</pool>
<security>
<security-domain>Password4APP</security-domain>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>
<timeout>
<blocking-timeout-millis>60000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>true</track-statements>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
</statement>
</datasource>
有一段时间我的应用程序无法获得数据库连接并记录这样的错误
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/DS_APP
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:146) ~[?:?]
at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:64) ~[?:?]
at ge.app.ws.util.DbManager.getDatabaseConnection(DbManager.java:55) ~[classes:?]
... 2 more
Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/DS_APP
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:690) ~[?:?]
at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:440) ~[?:?]
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:789) ~[?:?]
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138) ~[?:?]
at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:64) ~[?:?]
at ge.app.ws.util.DbManager.getDatabaseConnection(DbManager.java:55) ~[classes:?]
... 2 more
Caused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (60000 [ms])
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:570) ~[?:?]
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:632) ~[?:?]
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:604) ~[?:?]
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:624) ~[?:?]
at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:440) ~[?:?]
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:789) ~[?:?]
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138) ~[?:?]
at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:64) ~[?:?]
at ge.app.ws.util.DbManager.getDatabaseConnection(DbManager.java:55) ~[classes:?]
... 2 more
我读了很多关于这个错误的博客,但我的观点不同。从博客中我发现了一些问题:
- 也许你有连接泄漏。您没有关闭连接
Connection
我做了什么:我检查了我的代码的每一行,我确信每一行都在CallableStatement
关闭。
- 可能池中的所有连接都已在使用中,尝试增加连接池大小,默认为 20
- 我做了什么:当出现这个问题时,我检查了数据库端的连接,没有活动连接,所有连接都处于非活动状态,池中有 200 个连接,太多了,我最多同时有 30 个活动会话我有 60 秒的时间等待池中的连接空闲。
当我重新启动Wildfly
服务器时,问题解决了,但我对为什么会发生这个错误很感兴趣,如果将来会出现这个错误(我认为它们会再次发生)以及如何避免它们?