I am trying to migrate WAS7 application to Liberty profile. And now I am trying to get Datasource Mbean which is part of the existing code.I tried multiple options but I am always getting 'javax.management.InstanceNotFoundException'.
I am giving the sample code below. Please let me know if I miss something.
DataSource in Server.xml:
<library id="oracle-lib">
<fileset dir="lib" includes="ojdbc6.jar"/>
</library>
<dataSource jndiName="jdbc/db" id="oracleDB" type="javax.sql.DataSource">
<jdbcDriver javax.sql.DataSource="oracle.jdbc.pool.OracleConnectionPoolDataSource" libraryRef="oracle-lib" />
<connectionManager agedTimeout="10" maxIdleTime="1800" connectionTimeout="180" minPoolSize="10" maxPoolSize="1" reapTime="180"/>
<properties.oracle user="user" password="password"
url="jdbc:oracle:thin:@//db-server:1521/db"/>
</dataSource>
Java Code:
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName jvmQuery = new ObjectName("WebSphere:type=ConnectionPoolStats,name=dataSource[oracleDB]/ConnectionManager[default-0]")
Set mBeans = mbeanServer.queryMbeans(jvmQuery,null);
MBeanInfo beanInfo = mbeanServer.getMBeanInfo(jvmQuery);
I am not sure about the code, I am trying to keep the old code as much as possible.
Thank you, Biju
In your object name there is a minor case mismatch. The
C
onconnectionManager
should be lowercase, not uppercase.A few other things to check:
monitor-1.0
feature enabledConnectionPoolStats
MBean until there has been at least 1 connection obtained from your Connection Manager.jconsole
, which is a Java utility that comes with any JDK. After a request has been made to your data source / connection manager, you should see an MBean like this:To use
jconsole
you will need to enable thelocalConnector-1.0
feature. You can find more info on using JConsole with Liberty here:Connecting to Liberty by using JMX