Type the server-side export and publish: exportObject, createRegistry, rebind
Type the server-side export and publish: exportObject, createRegistry, rebind
Answer
PrimeService stub = (PrimeService) UnicastRemoteObject.exportObject(impl, 0); Registry registry = LocateRegistry.createRegistry(1099); registry.rebind("PrimeService", stub);
Port 0 means "any free port", and the stub carries whichever one was chosen. createRegistry runs the name service inside this JVM — the modern form, with no separate rmiregistry process. rebind, not bind, so a restart does not throw AlreadyBoundException.
JDK javadoc java.rmi.server.UnicastRemoteObject; java.rmi.registry.LocateRegistry