I am using pooledDataSources in my application. ObjectName of Mbean for PooledDataSource contain variable part along with it. for example:
ObjectName = com.mchange.v2.c3p0:type=PooledDataSource[z8kfsx9c4bily2r1i962|23696a1b]
has variable as z8kfsx9c4bily2r1i962|23696a1b and it changes everytime i restart my service. I have to get fixed ObjectName for my mbean for monitoring purpose. I am using jmx for monitoring. I tried to override vmid property but it seems its a not writable property. Did a lot of research on this but running out of luck.
My Jmx Configuration is as following:
<jmxtrans-agent>
<queries>
<!-- C3P0 -->
<query objectName="com.mchange.v2.c3p0:type=PooledDataSource" attribute="threadPoolNumTasksPending" resultAlias="cp.threadPoolNumTasksPending"/>
</queries>
</jmxtrans-agent>
Thanks in advance
By default, c3p0 JMX names look like this:
com.mchange.v2.c3p0:type=PooledDataSource,identityToken=<variable, opaque token>
In order to get a constant identifier, you must set ensure that the property dataSourceName
is set. The best way to do that is to give your DataSource
a name upon construction:
ComboPooledDataSource cpds = new ComboPooledDataSource("Jojo")
But you can also set dataSourceName
like any other c3p0 config property.
Then you'll have JMX names that look like:
com.mchange.v2.c3p0:type=PooledDataSource,identityToken=<variable, opaque token>,name=Jojo
Many JMX clients let you search on attributes, so this is sufficient to give yourself a permanent monitor.
If you really need a constant, fixed, JMX name, you can set the property
com.mchange.v2.c3p0.management.ExcludeIdentityToken=true
This can go in a c3p0.properties
file, as a System property, or as a HOCON/typesafe config path, depending how you are configuring c3p0. If you set this property and also set dataSourceName
(again, via a constructor or in your config), then your JMX name will be a predictable, fixed String, like
com.mchange.v2.c3p0:type=PooledDataSource,name=Jojo
It will be up to you to ensure these names are unique.
Note: com.mchange.v2.c3p0.management.ExcludeIdentityToken=true
is a new-ish feature, please be sure you are using the latest c3p0-0.9.5.1
For more details, see c3p0's JMX configuration docs.