Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Starting and stopping an RMI server

529432Dec 1 2009 — edited Dec 1 2009
I'm trying to figure out how to best stop and start my server.

My server class has two executions. One for starting and one for stopping.

Start Steps:

1) create my remote object ( an extension of UnicastRemoteObject )
2) create a registry ( LocateRegistry.create() )
3) bind my remote object

When I run this start method of my RMI server class, everything get's set up. I'm not doing any sort of waiting loop or anything to determine the lifecycle of my server. My understanding is that my rmiregistry, and my registered remote object, will continue to be available indefinitely. Perhaps this is incorrect.

Stop Steps:

When I want to stop the server, I'm calling my stop method. This is another invocation of my server class, so it's a separate JVM. In this stop method I want to do the following steps:

1) get the registry that I created earlier, by port number
2) get my remote object via reg.lookup()
3) unbind my remote obect ( reg.unbind() )
4) unexport my remote object ( UnicastRemoteObject.unexport ( myRemoteObj, true ) )

My concerns here are whether this makes sense. Does the unexport method work like this? i.e. from a remote handle to the object -- I'm not in the local JVM when the stop method runs. Also, does the rmiregistry "just die" at this point? It's not holding anything and when my method exits there's no reference to it anywhere. Except maybe in client code . . .
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 29 2009
Added on Dec 1 2009
5 comments
351 views