1、LocateRegistry.createRegistry创建了一个守护线程和一个空线程组;
public static void main(String[] args) throws Throwable{
Registry registry = LocateRegistry.createRegistry(8494);//左侧为添加了此行的控制台输出
Thread.currentThread().getThreadGroup().getParent().list();
}
2、本地绑定对象,多了两个线程,其中Reaper线程为非守护线程,main线程结束时不至于退出虚拟机;
public static void main(String[] args) throws Throwable{
Registry registry = LocateRegistry.createRegistry(8494);
//左侧为添加了此行的控制台输出
registry.bind(IRemoteA.RMI_NAME, UnicastRemoteObject.exportObject(new RemoteAB(), 8494));
Thread.currentThread().getThreadGroup().getParent().list();
}
3、UnicastRemoteObject.exportObject使用与创建Registry时不一样的端口,多了一个Accept线程;
public static void main(String[] args) throws Throwable{
Registry registry = LocateRegistry.createRegistry(8494);
//左侧为修改了端口的控制台输出
registry.bind(IRemoteA.RMI_NAME, UnicastRemoteObject.exportObject(new RemoteAB(), 0));
Thread.currentThread().getThreadGroup().getParent().list();
}
4、客户端远程调用,与普通的main进行比较;
public static void main(String[] args) throws Throwable{
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.rmi.registry.RegistryContextFactory");
System.setProperty(Context.PROVIDER_URL, "rmi://192.168.10.192:8494");
InitialContext context = new InitialContext();
IRemoteA ra = (IRemoteA)context.lookup(IRemoteA.RMI_NAME);
System.out.println(ra.doA());
Thread.currentThread().getThreadGroup().getParent().list();
}
5、远程绑定对象,与前面的本地绑定对象比较;
public static void main(String[] args) throws Throwable{
Registry registry = LocateRegistry.createRegistry(8494);
//registry.bind(IRemoteA.RMI_NAME, UnicastRemoteObject.exportObject(new RemoteAB(), 8494));
LocateRegistry.getRegistry("192.168.10.192", 8494).bind(IRemoteA.RMI_NAME,
UnicastRemoteObject.exportObject(new RemoteAB(), 8494));
Thread.currentThread().getThreadGroup().getParent().list();
}