Who needs rmiregistry?

Java Remote Method Invocation (RMI) contains a tool rmiregistry to run a stand-alone remote object registry. According to the RMI tutorial, rmiregistry is normally used in an RMI application.

I wonder why. It’s actually almost as simple to run the remote object registry within the RMI server. You only have to use java.rmi.registry.LocateRegistry#createRegistry(int port) method like this:

Registry registry = LocateRegistry.createRegistry(port);
registry.bind("Foo", stub);

Here is a complete example.

This is also more efficient since you don’t have to start a separate JVM for the registry. Running the registry within the RMI server doesn’t even require an extra thread, the registry is just another remote object.

Does anyone know about any sensible reasons for using rmiregistry?

This entry was posted in Java. Bookmark the permalink.