When exporting an object I find that both this
LocateRegistry.createRegistry(1099);
ObjectToExport obj = new ObjectToExport();
UnicastRemoteObject.exportObject(obj, 1099);
Naming.rebind("ObjectName", obj);
and this
LocateRegistry.createRegistry(1099);
ObjectToExport obj = new ObjectToExport();
Naming.rebind("ObjectName", UnicastRemoteObject.exportObject(obj, 1099));
work. In the first I don't use the return value of exportObject
and in the second I do. Is there a difference between these 2 ways of exporting an object? The API only says that the return value is the remote object stub
.
There is no difference at the export step, but you're also binding the object, and there's a difference at this step. In the first step you're passing the actual object; in the second, the stub. However the semantics of RMI are that exported remote objects are passed to remote methods as their own stubs, so the actual effect at the Registry is the same.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.