BEA Logo BEA WebLogic Server Release 6.1

  BEA Home  |  Events  |  Solutions  |  Partners  |  Products  |  Services  |  Download  |  Developer Center  |  WebSUPPORT

 

  |  

  WebLogic Server Doc Home   |     Partners' Guide   |   Previous Topic   |   Next Topic   |   Contents   |   View as PDF

Working with WebLogic Server MBeans

 

The following sections provide information about how to work with specific WebLogic Server MBeans:

 


Overview

Note: Using WebLogic JMX Services provides detailed information and code samples for working with WebLogic Server MBeans. If you are unfamiliar with the JMX API, please begin by reading that book.

The basic steps for working with MBeans in WebLogic Server are as follows:

  1. Obtain the MBeanHome interface of the Administration Server or individual WebLogic Server instance. For more information, refer to Accessing WebLogic Server MBeans in the Using WebLogic JMX Services guide.

  2. If your application must use pure-JMX method calls, obtain the MBeanServer interface from MBeanHome.

  3. Obtain the individual MBeans that you want to work with.

If you wish to use JMX notifications in your application, see Using MBean Notifications for details on setting up listeners and registering the listeners with WebLogic MBeans.

If you wish to deploy your own custom MBeans, refer to Accessing WebLogic Server MBeans.

The remaining sections describe how to use specific MBeans for different WebLogic Server APIs.

 


Using JDBC Profiling 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 API documentation 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:

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 =
          (JDBCConnectionPoolMBean)home.getConfigurationMBean(poolName,
            "JDBCConnectionPoolConfig");
mbean.setConnLeakProfilingEnabled(true);
mbean.setSqlStmtParamLoggingEnabled(true);
mbean.setSqlStmtMaxParamLength(maxLen);
...

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 =
          (JDBCConnectionPoolRuntimeMBean)home.getRuntimeMBean
                    (poolName,"JDBCConnectionPoolRuntime");
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,
                    profilesPerStep);
          // 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 page