我正在使用JMX获取Weblogic中的线程数但发生错误。 这是我的代码:
import java.util.Hashtable;
import javax.management.MBeanServer;
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 javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
public class JMXClient {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static ObjectName service;
//Update correct port
private static String port = "7001";
//Update localhost if server is accessed remotely
private static String url = "t3://localhost:7001";
// Update hostname if server is accessed remotely
private static String hostname = "localhost";
private static String username = "weblogic";
private static String password = "12345678";
// server name can differ from host name
private static String serverName = "AdminServer";
/*
* Initialize connection to the Runtime MBean Server
*/
private static void init() throws IOException, MalformedURLException {
String protocol = "t3";
Integer portInteger = Integer.valueOf(port);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.runtime";
//JMXServiceURL serviceURL = new JMXServiceURL(url);
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);
Hashtable env = new Hashtable();
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.runtime.JRockitRuntimeMBean");
connector = JMXConnectorFactory.connect(serviceURL, env);
connection = connector.getMBeanServerConnection();
try {
service = new ObjectName("com.bea:Name="+serverName + ",Type=ServerRuntime");
} catch (MalformedObjectNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void getTotalNumberOfThreads() {
try {
init();
Long totalNumberOfThreads = (Long) connection.getAttribute(service,"TotalNumberOfThreads");
System.out.println("totalNumberOfThreads is: " + totalNumberOfThreads);
connection.invoke(service, "start", new Object[] {}, new String[] {});
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Invoke required methods
JMXClient.getTotalNumberOfThreads();
}
}
错误是:
java.net.MalformedURLException: Unsupported protocol: t3
at javax.management.remote.JMXConnectorFactory.newJMXConnector(Unknown Source)
at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
我不知道为什么会这样。
当我使用weblogic.management.remote
获取应用程序服务器的状态时,一切正常,但是对于线程数,它没有回答。
答案 0 :(得分:1)
我把所有这五个罐放在类路径中来解决类似的问题:
<include name="wlclient.jar" />
<include name="wljmsclient.jar" />
<include name="wls-api.jar"/>
<include name="wljmxclient.jar"/>
<include name="wlconnector.jar"/>
答案 1 :(得分:0)
实际上,您仅需要以下罐子: \ Oracle_Home \ wlserver \ server \ lib \ wljmxclient.jar \ Oracle_Home \ wlserver \ server \ lib \ weblogic.jar
它与我一起使用默认值和sql提供程序。
答案 2 :(得分:0)
我在WLS12.2.1.3中遇到了同样的问题,仅在将/wlserver/server/lib/wlthint3client.jar文件添加到库中后修复了该问题。