CanJBossTellMeWhenIDontCloseAConnection

本文介绍了如何在JBoss中配置连接、语句和结果集的监控,确保在使用预编译语句缓存和避免数据库游标泄露时正确关闭连接、语句和结果集。此外,还提供了在生产环境和压力测试时禁用这些监控的方法。
转载自: [url]http://community.jboss.org/wiki/CanJBossTellMeWhenIDontCloseAConnection[/url]

[color=red]Can JBoss AS tell me when I don't close connections, statements or resultsets?[/color]
Yes.
[b]Connections[/b]

For connections the configuration is in deploy/transaction-service.xml
<attribute name="Debug">true</attribute>


Starting with 4.0.0, the configuration is in deploy/jbossjca-service.xml
<!-- 
| The CachedConnectionManager is used partly to relay started UserTransactions to
| open connections so they may be enrolled in the new tx.
-->
<mbean code="org.jboss.resource.connectionmanager.CachedConnectionManager"
name="jboss.jca:service=CachedConnectionManager">
<depends optional-attribute-name="TransactionManagerServiceName">jboss:service=TransactionManager</depends>

<!-- Enable connection close debug monitoring -->
<attribute name="Debug">true</attribute>

</mbean>


[b]Statements and ResultSets[/b]

For statements (and from 3.2.4 ResultSets) you can add the following to your -ds.xml (data source xml: oracle-ds.xml, and so on)
 <track-statements>true</track-statements>

Like this:

<!--pooling parameters-->
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>

<blocking-timeout-millis>60000</blocking-timeout-millis>
<idle-timeout-minutes>180</idle-timeout-minutes>
<track-statements>true</track-statements>

Closing statements and ResultSets is important if you want to use prepared statement caching and/or don't won't to leak cursors in your database.

[b]Servlets and JSP[/b]

From from 3.2.4 this checking is available in the web layer.
Enable the CachedConnectionValve by uncommenting the following in deploy/jbossweb-xxx.sar/server.xml:
<!-- Check for unclosed connections -->
<Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve"
cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager" ></Valve>

NOTE: From 4.0.0 the CachedConnectionValve should be configured this way:
<Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve"
cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
transactionManagerObjectName="jboss:service=TransactionManager" ></Valve>

JBoss 4.0.0 distribution still had the previous configuration that woulld cause a NullPointerException in CachedConnectionValve.checkTransactionComplete(CachedConnectionValve.java:198).
Once the valve is enabled, the CachedConnectionManager must be registered in deploy/jbossweb-xxx.sar/META-INF/jboss-service.xml.

At the end of the file, uncomment:
<depends>jboss.jca:service=CachedConnectionManager</depends>

[b]Production and Stress Testing[/b]
In production you will want to turn these off. You should have found all your leaks during development.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值