如何记录Tomcat 7 JDBC连接池,创建连接 [英] How to log Tomcat 7 JDBC connection pool, connection creation

查看:112
本文介绍了如何记录Tomcat 7 JDBC连接池,创建连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我们正在使用Tomcat 7 JDBC连接池,但我正在尝试调试打开和关闭的数据库连接似乎过多.在数据源上调用getConnection()导致打开新连接而不是从池中借用现有连接时,如何记录日志?

I'm trying to debug what seems to be an excessive number of database connections being opened and closed despite the fact that we are using the Tomcat 7 JDBC connection pool. How can I log when calling getConnection() on the data source results in a new connection being opened versus an existing connection being borrowed from the pool?

推荐答案

我今天也遇到了类似的情况.我通过slf4j登录,而我的问题是由休眠引起的.

I have faced a similar case today. I log through slf4j, and my problem was caused by hibernate.

我要做的是在日志配置中设置调用JDBC连接getter的空间.幸运的是,对于休眠模式,那里有调试级别的日志.

What I've done is setting up in the log configuration the space where the JDBC connection getter is called. Fortunately, for hibernate there are logs at debug level there.

<logger name="org.hibernate.engine.jdbc">
    <level value="debug"/>
</logger>

我的猜测是,对于您的情况,您可以尝试对调用JDBC池getter的名称空间执行等效的操作.可能是这样的:

My guess is that for your case you can attempt to do something equivalent with the namespace where your JDBC pool getter is invoked. It could be something like this:

<logger name="org.apache.tomcat.jdbc.pool">
    <level value="debug"/>
</logger>

我希望这会有所帮助.有了休眠,我得到的结果是这样的:

I hope this helps. With hibernate I get something like this as a result:

DEBUG 02.07.2015 16:36:50,571 http-bio-8080-exec-33 (org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection():212) [] - Obtaining JDBC connection
DEBUG 02.07.2015 16:36:50,601 http-bio-8080-exec-6 (org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection():218) [] - Obtained JDBC connection
DEBUG 02.07.2015 16:36:50,627 http-bio-8080-exec-10 (org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection():218) [] - Obtained JDBC connection
DEBUG 02.07.2015 16:36:50,643 http-bio-8080-exec-32 (org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions():139) [] - Could not open connection [n/a]
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
    at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:114)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

...

这篇关于如何记录Tomcat 7 JDBC连接池,创建连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆