Java JBOSS AS 7.1.1. 最终关闭泄漏的连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24884528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:21:26  来源:igfitidea点击:

JBOSS AS 7.1.1.Final Closing Leaked Connections?

javajbossdatabase-connectionjboss7.xconnection-pooling

提问by Ashish Kataria

I have already done the following settings in standalone.xml as:

我已经在 standalone.xml 中做了以下设置:

<datasource jta="true" jndi-name="java:jboss/datasources/myDS" pool-name="java:jboss/datasources/myDS" enabled="true" use-ccm="true">
<cached-connection-manager debug="true" error="true"/>

Therefore, I am also getting the messages like "Closing a connection for you" as:

因此,我也收到“为您关闭连接”之类的消息:

INFO  [org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager] (http--0.0.0.0-8080-160) IJ000100: Closing a connection for you. Please close them yourself: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@5cdb81dc: java.lang.Throwable: STACKTRACE
    at org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl.registerConnection(CachedConnectionManagerImpl.java:265)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:495)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)

Still, Sometimes my pool gets exhausted. It runs out of connections beyond 200 as defined. Why?

尽管如此,有时我的游泳池会耗尽。它用完了超过 200 个定义的连接。为什么?

<min-pool-size>30</min-pool-size>
<max-pool-size>200</max-pool-size>

There is no way, that my application needs these much connections. There is surely a connection leakage. And If it is, Why jboss is not closing it by it's own when I have enabled the setting as i said above:

没有办法,我的应用程序需要这么多连接。肯定有连接泄漏。如果是这样,当我启用上述设置时,为什么 jboss 没有自行关闭它:

<datasource jta="true" jndi-name="java:jboss/datasources/myDS" pool-name="java:jboss/datasources/myDS" enabled="true" use-ccm="true">
<cached-connection-manager debug="true" error="true"/>

How to resolve?

如何解决?

Thanks.

谢谢。

采纳答案by Neeraj

JBoss can not close all leaked connection.

JBoss 无法关闭所有泄漏的连接。

You need to find leaked connection by checking logs after enabling JCA logging. I resolved connection leak by this way.

您需要在启用 JCA 日志记录后通过检查日志来查找泄漏的连接。我通过这种方式解决了连接泄漏。

<logger category="org.jboss.jca">
????????????????<level name="DEBUG"/>
</logger>

You will get entries like below in logs

您将在日志中获得如下条目

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: getConnection(null, null) [1/100] -->It means taking connection from pool.

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: getConnection(null, null) [1/100] -->这意味着从池中获取连接。

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: returnConnection(607e334, false) [1/99]--> It means returning connection to pool

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: returnConnection(607e334, false) [1/99]-->表示返回连接池

You can check which query is not returning connetion to pool and check your application from where that query is being executed. Fix it.

您可以检查哪个查询未将连接返回到池,并从执行该查询的位置检查您的应用程序。修理它。

回答by bkelly1984

A bit more information to Neeraj's answer.

Neeraj 的回答的更多信息。

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: getConnection(null, null) [1/100]

The [1/100] at the end is [active connections/available connections] where:

最后的 [1/100] 是 [活动连接/可用连接],其中:

active connections = createdCount - destroyedCount

available connections = maxPoolSize - inUseCount