Hi,

Jay SenSharma

Jay SenSharma

Many times we want to collect the Runtime statistics of our Application components like EJB’s. Here is a simple JMX example code to monitor the “EntityBean” Runtime informations.

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import javax.naming.Context;
import javax.naming.InitialContext;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;
import weblogic.management.runtime.EJBPoolRuntimeMBean;
import weblogic.management.runtime.EntityEJBRuntimeMBean;
public class EntityMonitor
{
String url=”t3://localhost:9001″; // url for managed server
String username=”weblogic”;
String password=”weblogic”;
InitialContext ctx=null;
void getContext()throws Exception
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, “weblogic.jndi.WLInitialContextFactory”);
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, username );
env.put(Context.SECURITY_CREDENTIALS, password);
ctx = new InitialContext(env);
MBeanHome home_x = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
Set set=home_x.getMBeansByType(“EntityEJBRuntime”);
Iterator it=set.iterator();
while(it.hasNext())
{
EntityEJBRuntimeMBean entity=(EntityEJBRuntimeMBean)it.next();
System.out.println(“nntEntity::”+entity);
EJBPoolRuntimeMBean poolRuntime=entity.getPoolRuntime();
System.out.println(“ntEJBPoolRuntimeMBean :”+poolRuntime);
System.out.println(“ntgetPooledBeansCurrentCount(): “+poolRuntime.getPooledBeansCurrentCount());
System.out.println(“ntgetAccessTotalCount(): “+poolRuntime.getAccessTotalCount());
System.out.println(“ntgetDestroyedTotalCount(): “+poolRuntime.getDestroyedTotalCount());
System.out.println(“ntgetIdleBeansCount(): “+poolRuntime.getIdleBeansCount());
System.out.println(“ntgetBeansInUseCount(): “+poolRuntime.getBeansInUseCount());
System.out.println(“ntgetBeansInUseCurrentCount(): “+poolRuntime.getBeansInUseCurrentCount());
System.out.println(“ntgetWaiterTotalCount(): “+poolRuntime.getWaiterTotalCount());
System.out.println(“ntgetWaiterCurrentCount(): “+poolRuntime.getWaiterCurrentCount());
System.out.println(“ntgetTimeoutTotalCount(): “+poolRuntime.getTimeoutTotalCount());
}
}
public static void main(String []args)throws Exception
{
EntityMonitor rep = new EntityMonitor ();
rep.getContext();
}
}
———————————-
.
.

Regards
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.