UnicastRemoteObject class 的构造函数是做什么的

what does the constructor of UnicastRemoteObject class do

我对 UnicastRemoteObject class 有一些疑问。 采取以下代码:

public class MaxImpl extends UnicastRemoteObject implements Max{
public MaxImpl () throws RemoteException {}
    @Override
    public int getMax(int[] A) throws RemoteException {
     // ...
        return max;
    }
public static void main(String[] args) {
        try {
            LocateRegistry.createRegistry(1099);
            MaxImpl max  = new MaxImpl();
            Naming.rebind("maximum", max);
        } catch (RemoteException ex) {
            System.out.println(ex.getMessage());
        } catch (MalformedURLException ex) {
            System.out.println(ex.getMessage());
        }
    }

}

下面的语句是做什么的:

MaxImpl max  = new MaxImpl();
  1. 生成存根。
  2. 生成一个存根并创建一个远程对象,以便它可以接收 从远程客户端调用其远程方法。

上面的代码无限执行,为什么?我想有一个循环:

while(true){  ServerSocket server = ...; }

generate a stub.

没有

generate a stub and create a remote object so that it can receive invocations of its remote methods from remote clients.

没有

导出远程对象,它包括:

  1. 打开一个ServerSocket
  2. 启动一个线程侦听该套接字。
  3. 创建 包含 IP 地址、在 (1) 中使用的端口和远程对象标识符的存根对象。

请注意,(1( 和 (2) 可以在使用同一端口的远程对象之间共享,因此可能不会像上面那样发生。

现在 (2) 处线程的存在将阻止 JVM 退出。