weblogic中通过JMX获取执行线程的详细信息

//来源:   http://middlewaremagic.com/weblogic/?p=549

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+"> :..........Length: "+executeQueueRT.length);
			 
			for(int k=0;k: 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();
	}
}

 



已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐
  • —软件人才免语言低担保 赴美带薪读研!—



你可能感兴趣的:(weblogic,中通,jmx)