An RMI registry exists to solve the RMI bootstrap problem, and itβs just that you can only get a remote stub using a remote method call, and to make a remote method call you need a remote stub. The registry link provided by LocateRegistry.getRegistry() solves this problem (and is used inside Naming.lookup() if you use this API). [Note that this stub was not received using the remote method: it is synthesized locally using the host: port you provide. If they are not correct, you will not know until you use the registry stub.]
You have several options for solving the RMI bootstrap problem:
Use the RMI registry.
Use an LDAP server through JNDI with an LDAP provider.
Use UnicastRemoteObject, serialize the stub obtained by exporting the object, and use a shared file or socket or sneakernet to make the stub available to clients.
Use RMI activation; serialize the stub received when you registered the activated information and distribute it to all clients in the file along with the client application. From the point of view of the distribution of the stub, this is much simpler than (3), because the stub remains constant for the life of the application, while in (3) you must redo the stub with each export.
You can see that the registry is by far the easiest option. Please note that you only need to use it to solve the boot problem. When you have a stub, your own remote application methods can return additional objects: you do not need more than one remote object in the registry. You can consider this as a remote factory object.
source share