有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    [What's the] difference between java.rmi.Naming and java.rmi.registry.LocateRegistry

    不同之处在于nameNaming.rebind()字段是parsed as an URL,而Registry.rebind()字段是"name to associate with the remote reference"LocateRegistry.getRegistry()调用假定注册表位于本地主机上的默认端口,而Naming.rebind()允许您指定要使用的注册表

    在Java 1.6下Naming.rebind()name解析为URL,并使用注册表的主机/端口调用Naming.getRegistry()。调用LocateRegistry.getRegistry(host, port)

    public static void rebind(String name, Remote obj) throws RemoteException, MalformedURLException 
        ParsedNamingURL parsed = parseURL(name);
        Registry registry = getRegistry(parsed);
        if (obj == null)
            throw new NullPointerException("cannot bind to null");
        registry.rebind(parsed.name, obj);
    }
    ...
    
    private static Registry getRegistry(ParsedNamingURL parsed) throws RemoteException {
        return LocateRegistry.getRegistry(parsed.host, parsed.port);
    }
    
  2. # 2 楼答案

    如果您查看源代码,您将看到以下内容:

    public static void rebind(String name, Remote obj)
    throws RemoteException, java.net.MalformedURLException {
        ParsedNamingURL parsed = parseURL(name);
        Registry registry = getRegistry(parsed);
    
        if (obj == null)
            throw new NullPointerException("cannot bind to null");
    
        registry.rebind(parsed.name, obj);
    }
    

    免责声明:代码取自JDK而非我自己的impl

    类似问题here