An attempt to create more than a single registry in the same VM is failing.Working as designed. You can't create more than one Registry per JVM. This is because of what it says in the Javadoc: the Registry instance is exported with a well-known object identifier, an ObjID instance constructed with the value ObjID.REGISTRY_ID.'
How to stop the existing running RMI registry and re-start the RMI registry with same port number?You can do it with UnicastRemoteObject.unexportObject(), supplying the result you got from createRegistry(), but why? Why not just leave it running and bind/rebind/unbind things from it?
Can i do registry.unbind("xx") and registry.bind("xxx") again for starting the RMI registry on the same port number ?That doesn't even make sense. 'registry' is the registry you are trying to stop.
I tried the above code, it gives below mentioned ExportException.So this was the 2nd Registry, so it failed. Of course. Trying to create two Registries in the same JVM isn't going to work, and trying to create a 2nd Registry and then immediately unexport it doesn't make any sense whatsoever. I don't understand any of this. I don't know why you think you need a 2nd Registry at all. You don't.
It is in fact possible to create more than one registry in a JVM; just call LocateRegistry.createRegistry(port) with different port numbers.No it isn't. You get the ExportException that the OP is suffering from. Clearly you haven't actually tried it, nor read the thread properly.
EJP wrote:Of course, that never happens to me. :-)
Fancy that. Completely forgot what I wrote five years ago. How unusual ;-)