• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

shut down rmiregistry

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remotely started up a RMI registry: Process p = Runtime.getRuntime().exec("ssh "+host+"; cd "+path+" ; java Server");

public class Server(){
Exit(){
System.exit(0);
}
main(){
Registry registry = LocateRegistry.createRegistry(1099);
.....
}
}

I want to using the Client to shut down the Server through RMI call. The Server implemented a method "Exit()"

public class Client{

main(){
...
Object ob =(...)Naming.lookup(url);
ob.Exit();
}

}
but it doesn't work. There is an Exception -java.io.EOFException. Can anybody tell me why ?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the server disappears in the middle of an RMI call, it's no surprise you're seeing an exception on the client side! I'm guessing you're just calling System.exit() in the remote method. Instead, you should ideally call UnicastRemoteObject.unexportObject(obj, false) on all of your live servants, and then start a new thread which sleeps for a few seconds (to give the call to Exit() time to return, and then calls Exit; i.e.,



The empty catch blocks are OK in this case; you really don't care if there are errors, you just want to shut down.
 
Xiaoyan Sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ernest, Thank you for reply!

I got the following from Internet. The thread shouldn't be in the catch {}. I tried this quit(), it works just fine.

public void quit() throws RemoteException {
System.out.println("quit");
Registry registry = LocateRegistry.getRegistry();
try {
registry.unbind(_SERVICENAME);
UnicastRemoteObject.unexportObject(this, false);
} catch (NotBoundException e) {
throw new RemoteException("Could not unregister service, quiting anyway", e);
}

new Thread() {
@Override
public void run() {
System.out.print("Shutting down...");
try {
sleep(2000);
} catch (InterruptedException e) {
// I don't care
}
System.out.println("done");
System.exit(0);
}

}.start();
}
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look again at my code -- the thread is not in the catch block.
 
Xiaoyan Sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, Ernest. I didn't see your code clearly. You are right. They are the same, and it can work.
 
Squanch that. And squanch this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic