Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't see JMX entries in jconsole when using Tomcat JDBC Connection Pool

we're evaluating switching over from the C3P0 connection pool to the Tomcat JDBC Connection Pool (as described here).

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).

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.

What am I missing?

I'm running a fairly standard Java6/Spring/Hibernate app by the way.

like image 829
Darren Greaves Avatar asked Oct 05 '10 15:10

Darren Greaves


1 Answers

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

You may use this spring config for export pool information to 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

like image 58
leonidv Avatar answered Sep 22 '22 23:09

leonidv