Weblogic MBean Example (ExecuteQueueRuntime)

Aim
The aim of this tutorial is to connect to a Weblogic MBean from a remote client and extract some Information We will be connecting to the ExecuteQueueRuntime Mbean and getting the idle thread count . Leave any questions or problems as comments and I will endeavour to answer them.

Assumptions
This article assumes that you have a compatible version of Weblogic installed and running and you have a compatible version of the JDK aswell.

Versions used in this example
Sofware/ComponentImage
Weblogic Server 8.1N/A
JDK 1.4.2N/A
Links to these files can be found here

In the source file you are connecting to the admin port on weblogic.

Please make sure the the java versions on your weblogic server and the java version on the client machine are the same or else you will get incompatible serialVersionUID errors like the ones below.

<9/09/2009 01:22:39 PM EST> <Error> <RJVM> <BEA-000503> <Incoming message header or abbreviation processing failed java.io.InvalidClassException: javax.management.ObjectName; local class incompatible: stream classdesc serialVersionUID = -5467795090068647408, local class serialVersionUID = 1081892073854801359
.....

>


Write and Compile the Example
  1. Write the client code and save it as WeblogicMBeanExample.java in your working directory. Make sure you edit the url, username and password to match your system. The url is basically your weblogic admin url.
     1. import java.util.*;
     2. import java.rmi.RemoteException;
     3. import javax.naming.*;
     4. import java.io.*;
     5. 
     6. import weblogic.jndi.Environment;
     7. import weblogic.management.MBeanHome;
     8. import javax.management.ObjectName;
     9. import weblogic.management.runtime.ExecuteQueueRuntimeMBean;
    10. 
    11. public class WeblogicMBeanExample{
    12.     
    13.     public static void main(String[] args){
    14.         new WeblogicMBeanExample().GoBeans();
    15.     }
    16. 
    17.     public void GoBeans(){
    18.         MBeanHome home;
    19.         String url = "t3://myhost:7001";
    20.         String username = "weblogic";
    21.         String password = "password123";
    22. 
    23.         ExecuteQueueRuntimeMBean mbeanExecuteQueueRuntime;
    24.         Set mbeanSet;
    25.         Iterator mbeanIterator;
    26. 
    27.         try{
    28.             Properties prop = new Properties();
    29.             prop.put(Context.INITIAL_CONTEXT_FACTORY, 
    30.                 "weblogic.jndi.WLInitialContextFactory");
    31.             prop.put(Context.PROVIDER_URL, url);
    32.             prop.put(Context.SECURITY_PRINCIPAL, username);
    33.             prop.put(Context.SECURITY_CREDENTIALS, password);
    34.         
    35.             Context ctx = new InitialContext(prop);
    36.             home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
    37.             mbeanSet = home.getMBeansByType("ExecuteQueueRuntime");
    38.             mbeanIterator = mbeanSet.iterator();
    39. 
    40.             while(mbeanIterator.hasNext()){
    41.                 mbeanExecuteQueueRuntime = 
    42.                                 (ExecuteQueueRuntimeMBean)mbeanIterator.next();
    43.                 ShowInfo(mbeanExecuteQueueRuntime);
    44.             }
    45.         }catch (Exception e){
    46.             e.printStackTrace();
    47.         }
    48.         
    49.     }
    50.     
    51.     static void ShowInfo(ExecuteQueueRuntimeMBean meqr){
    52.         try{
    53.             System.out.print(meqr.getName());
    54.             System.out.print("\t\t"+meqr.getExecuteThreadCurrentIdleCount());
    55.             System.out.print("\t\t"+meqr.getParent().getName());
    56.         }catch(Exception e){
    57.             System.out.print("\t\tError");
    58.             e.printStackTrace();
    59.         }
    60.         finally{
    61.             System.out.println("\n");
    62.         }
    63.     }
    64. }
    Hide line numbers

  2. You need the weblogic.jar to compile this. I strongly suggest you take a copy of the weblogic.jar file from the weblogic server you are trying to connect to. This will limit any incompatibility issues. Copy the weblogic.jar file to your working directory. It should be with your source file.

  3. Now open a promt to where you saved the file and compile it.

    javac -classpath .;weblogic.jar WeblogicMBeanExample.java

  4. Now run it.

    java -cp .;weblogic.jar WeblogicMBeanExample

4 comments:

Anonymous said...

Hi


Sub : Tech Blog Link Request - http://www.adamsinfo.com

For leveraging traffic from the internet, I have manually collected a list of quality blogs and sites with whom I am interested in getting associated.

I liked your Site/blog and i'm interested in having my blog's text link in your blog roll.

Please let me know your interest in this association and then we can move towards next step.

Sincerely,

Webmaster
Adamsinfo.com
seo@apnicsolutions.com

Anonymous said...

This is good, but when can you go one for glassfish and maybe using jmx?

Lada said...

Thank you, save me a lot work ;-)

Naviya Nair said...

Very interesting and good Explanation
ASP NET Training
ASP NET Training
ASP NET Online Training
C-Sharp Training
Dot Net Training in Chennai
Online .Net Training


MVC Training
WCF Training
Web-API Training
LINQ Training
Entity Framework
Training

Dot Net Interview Questions