How can i remove the remote object from the RMI runtime

3.9k Views Asked by At

When i shutdown the RMI server program by using, serverReg.unbind("LibraryServer"); it only remove the bound of remote object and it's key 'LibraryServer. If i start the server same time it give me an exception ObjID already in use. How can i entirety remove remote object from the registry ?. Binding statement of Remote object and it's key is,

serverReg.rebind("LibraryServer", new RemoteFactoryImpl());
2

There are 2 best solutions below

0
user207421 On BEST ANSWER

When I shutdown the RMI server program by using, serverReg.unbind("LibraryServer"); it only remove the [binding] of remote object and it's key 'LibraryServer.

Correct.

If i start the server same time it give me an exception ObjID already in use.

I'd like to see that exception and stack trace.

How can I entirety remove remote object from the registry?

You have already done so. You may be looking for a way to unexport the remote object, which is given by UnicastRemoteObject.unexportObject().

However the ObjID already in use error can realistically only be coming from trying to export another Registry from a JVM in which you have already exported one. Which doesn't correspond with your description at all.

1
ccc On

Ok, i found an answer for that, unbined method only removes connection between remote object and its key. So cannot restart the rmi server with same remote object because first remote object still in the registry. By using unexportObject method of UnicastRemoteObject class can be entirely remove remote object from registry. I found it from a post of this.

UnicastRemoteObject.unexportObject(serverReg, false);