java 使用 Tomcat JDBC 连接池时无法在 jconsole 中看到 JMX 条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3865445/
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
Can't see JMX entries in jconsole when using Tomcat JDBC Connection Pool
提问by Darren Greaves
we're evaluating switching over from the C3P0 connection pool to the Tomcat JDBC Connection Pool (as described here).
我们正在评估从 C3P0 连接池切换到 Tomcat JDBC 连接池(如此处所述)。
It appears to work as a connection pool but I can't seem to see any JMX entries for it when I run jconsole.
Out of the box C3P0 gives lots of operations and attributes via JMX, the Tomcat
JDBC Connection Pool gives none (for me).
它似乎作为一个连接池工作,但当我运行 jconsole 时,我似乎看不到任何 JMX 条目。
开箱即用的 C3P0 通过 JMX 提供了许多操作和属性,Tomcat JDBC 连接池没有提供(对我而言)。
According to the page linked above there is a jmxEnabled flag that defaults to true. I've set this explicitly but it seems to make no difference.
根据上面链接的页面,有一个 jmxEnabled 标志默认为 true。我已经明确设置了这一点,但似乎没有什么区别。
What am I missing?
我错过了什么?
I'm running a fairly standard Java6/Spring/Hibernate app by the way.
顺便说一下,我正在运行一个相当标准的 Java6/Spring/Hibernate 应用程序。
回答by leonidv
If you configure pool in your spring context, you should export bean manually. Autoexport works only if you confiugre pool in tomcat container and import it from JNDI. See http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#JMX
如果在 spring 上下文中配置池,则应手动导出 bean。仅当您在 tomcat 容器中配置池并从 JNDI 导入时,自动导出才有效。见http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#JMX
You may use this spring config for export pool information to JMX:
您可以使用此 spring 配置将池信息导出到 JMX:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
... skipped ...
</bean>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="beans">
<map>
<entry key="bean:name=DataSource" value="#{dataSource.getPool().getJmxPool()}"/>
</map>
</property>
</bean>
Config works only in Spring version 3.0 and above, because it uses spring expression language
Config 仅适用于 Spring 3.0 及以上版本,因为它使用的是 spring 表达式语言
回答by Sean
Do you see any entries under the tree
你看到树下的任何条目了吗
Catalina -> DataSource -> javax.sql.DataSource
This lists the number of active connections, idle connections, and a few other common stats. Other then that, what kind of information are you hoping to get out of monitoring?
这列出了活动连接数、空闲连接数和其他一些常见统计信息。除此之外,您希望通过监控获得哪些信息?
回答by bsnyder
Darren, if you don't see the object name under Catalina/DataSource/javax.sql.DataSource/<name>
in JConsole, then I wonder if the datasource is defined incorrectly or perhaps it was not connected to the database when Tomcat was started.
Darren,如果你Catalina/DataSource/javax.sql.DataSource/<name>
在JConsole下没有看到对象名称,那么我想知道数据源是否定义不正确,或者在Tomcat启动时它没有连接到数据库。
Bruce
布鲁斯
回答by Alex Uke
The placement of the javax.sql.DataSource
entry in MBeans of JConsole is:
javax.sql.DataSource
JConsole 的 MBeans 中条目的放置是:
Catalina
DataSource
/[Name_of_deployed_application]
// e.g. "/DomainService/[Host_name_of_the_deployed_application]
//e.g. "localhost"javax.sql.DataSource
Catalina
DataSource
/[Name_of_deployed_application]
// 例如“/域服务/[Host_name_of_the_deployed_application]
//例如“本地主机”javax.sql.DataSource