0
我在使用Jolokia与RMI服务一起使用时遇到问题。一旦RMI服务启动,Jolokia不再可以通过http访问。使用Jolokia代理与RMI服务器
我创建了一个例子类来重现问题:
package com.example.rmi;
import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
public class RMITest {
private class RMIService extends UnicastRemoteObject {
private static final long serialVersionUID = 1L;
protected RMIService() throws RemoteException {
super();
}
public void doStuff() {
System.out.println("Processing...");
}
}
public static void main(String[] args) throws RemoteException {
RMITest rmiServer = new RMITest();
rmiServer.init();
}
private void init() throws RemoteException {
RMIService rmiService = new RMIService();
try {
System.out.println("Starting RMI-Service...");
String hostname = InetAddress.getLocalHost().getHostName();
System.setProperty("java.rmi.server.hostname", hostname);
int port = 2005;
LocateRegistry.createRegistry(port);
Naming.rebind("rmi://" + hostname + ":" + port
+ "/RMIService", rmiService);
System.out.println("RMI-Service started!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果我改变的主要方法,以不启动RMI-服务,椒是通过HTTP URL http://127.0.0.1:8778/jolokia/再次访问:
public static void main(String[] args) throws RemoteException {
RMITest rmiServer = new RMITest();
//rmiServer.init();
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
该服务是一个可运行的jar。下面是我使用来启动应用程序的命令:
java -javaagent:jolokia-jvm-1.3.7-agent.jar=port=8778,host=localhost -jar RMITest-0.0.1-SNAPSHOT.jar
我从网上下载的官方网站椒剂:Jolokia Agent Download