Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple code to get the Execute Threads Details…Available in Different Servers…

Execute Threads has 5 Main Attributes…

1). Number : A unique identifier for the thread within the queue.
2). Total Requests: he number of requests that have been processed by this queue.
3). Current Request: A String representation of the request that this thread is currently processing.
4). Transaction: The transaction that the execute thread is currently working on behalf of.
5). User: The user the execute thread is currently working on behalf of.

CompleteWebLogicMonitoring .java

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.management.runtime.*;

public class CompleteWebLogicMonitoring {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;
static {
try {
service = new ObjectName(
"com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
}catch (MalformedObjectNameException e) {
throw new AssertionError(e.getMessage());
}
}
public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException {
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,port, jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();
}
public static ObjectName[] getServerRuntimes() throws Exception {
return (ObjectName[]) connection.getAttribute(service,"ServerRuntimes");
}

public void printNameAndState() throws Exception {
ObjectName[] serverRT = getServerRuntimes();
System.out.println(" Server   State");
int length = (int) serverRT.length;
for (int i = 0; i < length; i++) {
String name = (String) connection.getAttribute(serverRT[i],"Name");
String state = (String) connection.getAttribute(serverRT[i],"State");
System.out.println( name + " : " + state);
}
}

public void threadDump() throws Exception
{
ObjectName[] serverRT = getServerRuntimes();
int length = (int) serverRT.length;
for (int i = 0; i < length; i++)
{
String name = (String) connection.getAttribute(serverRT[i],"Name");
ObjectName executeQueueRT[] =  (ObjectName[]) connection.getAttribute(serverRT[i],"ExecuteQueueRuntimes");
System.out.println("n....<"+name+"> :<ExecuteQueueRuntimes>..........Length: "+executeQueueRT.length);

for(int k=0;k<executeQueueRT.length;k++)
{
ExecuteThread[] executeThreads=(ExecuteThread[])connection.getAttribute(executeQueueRT[k], "ExecuteThreads");
for(int j=0;j<executeThreads.length;j++)
{
String currReq=executeThreads[i].getCurrentRequest() ;
String threadName=executeThreads[i].getName();
String appName=executeThreads[i].getApplicationName()  ;
int servicedRequestTotalCount=executeThreads[i].getServicedRequestTotalCount();
System.out.println("getName                      : " +threadName);
System.out.println("getCurrentRequest            : " +currReq);
System.out.println("getApplicationName           : " +appName);
System.out.println("getServicedRequestTotalCount : " +servicedRequestTotalCount);
System.out.println(".......................................n");
}
}

}
}

public static void main(String[] args) throws Exception {
if(args.length < 4) {
System.out.println("<Usage>: java CompleteWebLogicMonitoring  adm-host  adm-port adm-username adm-password");
System.exit(0);
}
String hostname = args[0];
String portString = args[1];
String username = args[2];
String password = args[3];
CompleteWebLogicMonitoring s = new CompleteWebLogicMonitoring();
initConnection(hostname, portString, username, password);

s.printNameAndState();
s.threadDump();
connector.close();
}
}

OUTPUT:

C:DELETEBLOG_REPLYJMX_ThreadDump>java CompleteWebLogicMonitoring localhost 7001 weblogic weblogic
Server   State
AdminServer : RUNNING

….<AdminServer> :<ExecuteQueueRuntimes>……….Length: 1
getName                      : ExecuteThread: ‘0’ for queue: ‘weblogic.socket.Muxer’
getCurrentRequest            : Socket Reader Request
getApplicationName           : null
getServicedRequestTotalCount : 1
…………………………………

getName                      : ExecuteThread: ‘0’ for queue: ‘weblogic.socket.Muxer’
getCurrentRequest            : Socket Reader Request
getApplicationName           : null
getServicedRequestTotalCount : 1
…………………………………

getName                      : ExecuteThread: ‘0’ for queue: ‘weblogic.socket.Muxer’
getCurrentRequest            : Socket Reader Request
getApplicationName           : null
getServicedRequestTotalCount : 1
…………………………………

C:DELETEBLOG_REPLYJMX_ThreadDump>

——————————–

Thanks

Jay SenSharma

——————————-

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