Skip navigation.

WebLogic Server Partners' Guide

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents View as PDF   Get Adobe Reader

Using JDBC Profiling MBeans

The WebLogic Server management system uses Java Management Extensions (JMX) and Managed Beans (MBeans) to configure servers. The Programming WebLogic Management Services with JMX guide provides detailed information and code samples for working with WebLogic Server MBeans.

BEA provides several JDBC MBeans that you can use to store and analyze metrics for SQL statements, prepared statements, and JDBC connection leaks. The following sections describe how to enable and use JDBC profiling. For additional information, refer to the Javadoc for the following WebLogic Server MBeans and related classes:

Enabling JDBC Profiling

Before you can analyze SQL statements or connection leak profiles, you must enable profiling for the connection pool you want to observe. When profiling is enabled, the connection pool stores metrics in an external repository for later analysis.

Applications enable and disable JDBC profiling options using the JDBCConnectionPoolMBean. In addition to providing get/set methods for standard connection pool properties, JDBCConnectionPoolMBean provides the following methods for enabling and disabling profiling:

For information on obtaining MBeans in WebLogic Server, see "Accessing WebLogic Server MBeans" in Programming WebLogic Management Services with JMX. The following excerpt shows an application that obtains the JDBCConnectionPoolMBean and activates all profiling options. This example stores a maximum of 20 characters for each statement parameter:

// Obtain MBeanHome for the administration server.
JDBCConnectionPoolMBean mbean =

Accessing JDBC Profiles

Once you have enabled the desired profiling option(s), you can analyze the stored metrics using the JDBCStatementProfile and JDBCConnectionLeakProfile classes. Both of these profile classes can be easily obtained using the JDBCConnectionPoolRuntimeMBean.

JDBCStatementProfile stores the SQL statements and associated metrics (and optionally, bind parameters) for the connection pool. JDBCConnectionLeakProfile stores stack traces for leaked connections.

Obtaining all profiles at once may consume considerable resources. For this reason, applications should generally retrieve only a subset of profiles at a given time. You can accomplish this by first determining the total number of profiles in storage, then retrieving profiles in smaller subsets.

The following example shows a simple way to divide the number of profiles into smaller fractions.

// Obtain MBeanHome for the server that hosts the connection pool.
. . .
// Get the JDBCRuntimeMbean for the "testPool" connection pool.
String poolName = "testPool";
JDBCConnectionPoolRuntimeMBean mbean =
JDBCConnectionLeakProfile[] profiles = null; 
// Get the total number of available prepared statement cache profiles
int profileCount = mbean.getConnectionLeakProfileCount();
// Request profilesPerStep number of profiles
int profilesPerStep = 10;
// Begin with profile number profileIndex
int profileIndex = 0;
boolean done = (profileCount > 0);
while (!done) {
     // Get profiles
     profiles = mbean.getConnectionLeakProfiles(profileIndex,
     // Go through retrieved profiles
          for (int index = 0; index < profiles.length; index++) {
          // Get pool name
          String poolName = profiles[index].getPoolName();
          // Get stack trace
          String stackTrace = profiles[index].getStackTrace();
     profileIndex = profileIndex + profilesPerStep - 1;
     // Finish if number of retrieved profiles is
     // less then requested
     done = (profiles.lengh < profilesPerStep);


Back to Top Previous Next