| By Salma Saad | Article Rating: |
|
| October 26, 2005 07:15 PM EDT | Reads: |
26,136 |
The code above will work for the simplest situation where the admin server also hosts the JDBC application we're tracing, but for the situation where the admin server is independent from the managed server(s) and several independent JVMs are involved we'll need to get the admin MBeans home instead of the local MBeans home. The difference between the two is that the local home provides the MBeans for a single server while the admin home provides MBeans for all of the servers, which are administered by an administration server. To get the admin MBeans home instead of the local MBeans home, replace LOCAL_JNDI_NAME with ADMIN_JNDI_NAME in the code above.
Step 3
It's useful if you provide a way to turn the JDBC profiling on and off because profiling is expensive and you should turn it off if you don't need it. The profiling is off by default so you'll have to turn it on before you can trace any JDBC statements. Create a method such as the following:
public void configureJDBCAuditing(boolean isOn) {
try {
MBeanHome home = getMBeanHome();
//Retreive the bean to help us configure the Pool
JDBCConnectionPoolMBean mConfigBean =
(JDBCConnectionPoolMBean)home.getConfigurationMBean("MyPool","JDBCConnectionPoolConfig");
mConfigBean.setSqlStmtProfilingEnabled(isOn);
mConfigBean.setSqlStmtParamLoggingEnabled(isOn);
} catch (InvalidAttributeValueException iave) {
System.out.println("Invalid attribute while configuring tracing " + iave);
} catch (InstanceNotFoundException infe) {
System.out.println("Instance not found while configuring tracing " + infe);
}
}
In the code above we are also telling the connection pool that we want to see the parameters going into the SQL statements. This adds to the overhead of the tracing but provides us with some valuable information.
Step 4
After we have configured the JDBC pool to store the profiles we can go ahead and ask for them. Remember that the number of profiles retrieved will be equal to the number of SQL statements executed since you turned the profiling on and not equal to all of the SQL statements that have ever been executed by the MyPool ConnectionPool. The code below retrieves the profiles; the parameter maxProfiles indicates how many of the most recent profiles should be fetched. Create a method such as:
/** Pass in -1 to get all profiles */
public JDBCStatementProfile[] getProfiles(int maxProfiles) {
JDBCStatementProfile[] profiles = null;
try {
MBeanHome home = getMBeanHome();
JDBCConnectionPoolRuntimeMBean mbean =
(JDBCConnectionPoolRuntimeMBean)home.getRuntimeMBean("MyPool
","JDBCConnectionPoolRuntime");
int numProfiles = mbean.getStatementProfileCount();
int profilesIndex = 0;
//figure out index to start at and how many we want
if (maxProfiles != -1) {
profilesIndex = numProfiles - maxProfiles;
}else {
maxProfiles = numProfiles;
}
profiles =mbean.getStatementProfiles(profilesIndex,maxProfiles);
} catch (InstanceNotFoundException infe) {
System.out.println("Problem retrieving jdbc profiles " + infe);
}
return profiles;
}
The method getStatementProfiles of the JDBCConnectionPoolRuntimeMBean is missing from the WebLogic 8.1 API documentation, though it appears in the documentation for WebLogic 6.1. However, this appears to be a mistake since the method is available in 8.1 and a bug was fixed in this method in WebLogic 8.1 (CR094729 at http://e-docs.bea.com/wls/docs81/notes/resolved_sp01.html), which means that the method was meant to be included with WebLogic 8.1
Step 5
You can add a reset function so that you can clear the statement cache when you restart the server:
public void reset() {
MBeanHome home = getMBeanHome();
try {
JDBCConnectionPoolRuntimeMBean mbean =
(JDBCConnectionPoolRuntimeMBean)home.getRuntimeMBean("MyPool
","JDBCConnectionPoolRuntime");
//Remove everything from the cache
mbean.resetStatementProfile();
} catch (InstanceNotFoundException infe) {
System.out.println("Problem while resetting JDBC profiles " + infe);
}
}
Step 6
Iterate through the profiles to get the information you'd like to show (see Listing 1). This code would probably reside in the UI layer, such as in a JSP.
The Future of WebLogic JMX
WebLogic 9.0, which is a very recent release at the time of writing, supports JMX 1.2 instead of JMX 1.0, which was supported until WebLogic 8.1. In response to the change in the JMX specification, the WebLogic JMX API has changed quite a bit in 9.0 and the code in Listing 1 may generate deprecation warnings. When upgrading to 9.0 the JDBCDataSourceRuntimeMBean should replace the JDBCConnectionPoolRuntimeMBean. However, the vast majorities of legacy applications that are running on WebLogic are not using the 9.0 WebLogic Server at the time of writing, and probably will not do so for quite some time.
Published October 26, 2005 Reads 26,136
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Salma Saad
Salma started her career back in 1993, working on Steve Jobs NeXT platform and moved on to Java when it was at the ‘bleeding edge’. She has worked as a consultant for more than ten years, working primarily on website development projects for a large variety of clients. In addition to her fascination with everything technical she also has a strong interest in developing her leadership and management expertise. She enjoys living in Chicago and being the mother of two rugrats, ...um boys and is currently working for Arc Worldwide/Leo Burnett helping fortune 500 clients build awe-inspiring websites.
![]() |
Oscar Madrigal 11/23/05 08:17:44 PM EST | |||
Great tip but only log the succesfull statements, how can trace fails statements? |
||||
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo NY: Best Practices for Delivering Oracle Database as a Service
- BEA Updates WebLogic SOA Portal for Web 2.0 Era
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- Engine Yard Announces General Availability of PHP on Engine Yard Cloud and Support for Riak Distributed Database
- Research and Markets: Global Platform-As-A-Service Market Expected To Post Revenue of US$6.45 Billion in 2016 According To Latest Report
- Part 3 | Component Models in Java
- Component Models in Java | Part 2
- Tech Trends To Watch In May 2013
- Kevin Benedict’s What’s New in HTML5 – Week of May 19, 2013
- Services Orinted Architecture (SOA) Market
- BrightScope Releases Top 25 Technology Companies With the Best 401k Plans
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo NY: Best Practices for Delivering Oracle Database as a Service
- BEA Updates WebLogic SOA Portal for Web 2.0 Era
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- Velocity Technology Solutions Introduces IBM Power Systems Universal Cloud Services at COMMON 2013
- Engine Yard Announces General Availability of PHP on Engine Yard Cloud and Support for Riak Distributed Database
- Research and Markets: Global Platform-As-A-Service Market Expected To Post Revenue of US$6.45 Billion in 2016 According To Latest Report
- Component Models in Java | Part 1
- Part 3 | Component Models in Java
- Component Models in Java | Part 2
- Lessons to Learn from the Hibernate Core Implementation
- Tech Trends To Watch In May 2013
- Java vs C++ "Shootout" Revisited
- Where Are RIA Technologies Headed in 2008?
- Configuring Eclipse for Remote Debugging a WebLogic Java Application
- XA Transactions
- Migrating a JBoss EJB Application to WebLogic
- An Introduction to Abbot
- Cloud People: A Who's Who of Cloud Computing
- 'HTTP Session Replication Failure' Issues
- WebLogic Tutorial: "Integrating Apache Poi in WebLogic Server"
- Eclipse "Pollinate" Project to Integrate with Apache Beehive
- Monitoring and Controlling WebLogic Servers with WLST
- Failover and Recovery of Enterprise Applications - Part 1
























