我已经在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
即将结束。当我重新启动Wildfly
服务器时,问题得以解决,但是我对为什么会发生此错误,是否将来会再次出现此错误(我认为它们会再次发生)以及如何避免这些错误感兴趣?
答案 0 :(得分:0)
我最近遇到了同样的问题。 正如您提到的,此修复程序可能的解决方案是
我尝试通过将最大池大小设置为20来更改数据源配置, 但是在遇到第21个请求后,我遇到了同样的错误。
我在数据源配置中启用了统计信息,并在jboss console->数据源配置中验证了池统计信息,发现正在建立连接但没有关闭连接。
重新启动该错误将不会得到此错误,因为所有这些连接都将被刷新并且20个新的连接将随时可用。
因此,我尝试跟踪连接泄漏,并添加了以下配置,这些配置将手动关闭数据源连接并在出现连接泄漏时记录错误。 https://access.redhat.com/solutions/309913
它解决了我的问题,但这不是永久解决方案,因此重新检查代码以查看连接泄漏的位置。然后,我更改了代码以正确关闭数据源。
我以为这可以用,但是不行(初始代码):
try {
Connection dbConnect = dataSource.getConnection();
Statement stmt = dbConnect.createStatement();
ResultSet rs = stmt.executeQuery("select s from soething");
stmt.close();
dbConnect.close();
return something;
} catch (SQLException e) {
LOGGER.log(Level.INFO, e.getMessage());
return e.getMessage();
}
这将起作用(最终代码具有整齐封闭的数据源):
Statement stmt=null;
Connection dbConnect=null;
try {
dbConnect = dataSource.getConnection();
stmt = dbConnect.createStatement();
ResultSet rs = stmt.executeQuery("select s from soething");
return something;
} catch (SQLException e) {
LOGGER.log(Level.INFO, e.getMessage());
return e.getMessage();
}finally{
if (stmt != null) stmt.close();
if (dbConnect != null) dbConnect.close();
}