1

有没有办法(例如通过使用 JMX/MBeans)来测试 Tomcat 服务器的 JDBC 池连接?

4

2 回答 2

2

如果你想使用 JMX bean,你可以寻找这个 bean:

Catalina:type=DataSource,context=/[context],host=[hostname],class=javax.sql.DataSource,name="[your JNDI name]"

该 bean 有一个getConnection()返回javax.sql.Connection对象的方法。完成后记得调用close()它。

于 2012-08-04T02:49:20.687 回答
1

You did not specify which version of Tomcat you are using and what connection pool, so I feel free to assume you are using DBCP. In that case you can access a lot of the status values from the org.apache.commons.dbcp.BasicDataSource. You will have to do it from inside of your web application. Probably, the least invasive way is to throw in a JSP page that gets your pooled data source from JNDI, queries BasicDataSource for status values and displays them in a simple HTML table.

于 2012-08-03T20:08:10.620 回答