1) Start an rmiregistry on port 1100
2) Run the following code:
Code: Select all
import java.net.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class TestApp extends UnicastRemoteObject {
public TestApp () throws RemoteException {
}
public static void main (String args []) throws Exception {
System.out.println (register (new TestApp (), InetAddress.getLocalHost ().getHostName (), 1100, "Global"));
System.in.read (new byte[128]);
System.out.println ("Exiting main thread");
}
static String register (TestApp gate, String machine, int port, String genericname)
throws AlreadyBoundException, MalformedURLException, RemoteException {
String shortmachine = machine + ":"+port;
String name = "//" + shortmachine + "/" + genericname;
Naming.bind (name, gate);
return name;
}
}
If you run it with -agentlib:yjpagent then if you take a stack trace before hitting Enter you will see that RMI-Reaper is now a daemon thread. Pressing Enter now causes the message "Exiting main thread" to be displayed, followed by application exit.