Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: (Contractors) server shutdown and file close

 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I have not been able to figure out how to gracefully shut the RMI-based server down. I want to do this so that I can close my database file properly when exiting the server.
What is a good way to shut down an RMI server so that resources can be released? What are the issues here?
Thanks!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11865
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,
I have not seen any way of shutting down the RMI Server programatically.
I think the best you can do is derigister your own services, and check that no other services have been registered. They do a System.exit().
Regards, Andrew
 
Matt Rea
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
I have always been a fan of shutdown hooks to gracefully handle shutdowns in these types of cases. From memory it is something along the lines of:
Runtime localVM = Runtime.getRuntime(); localVM.addShutdownHook(cleanupThread );
cleanupThread is a inner class extending thread. All your cleanup and graceful shutdown code is in the run method. Even if you control-C to shutdown your server it will still run the shutdown hook.
regards,
Matt
 
Vitaly Zhuravlyov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not think that the Shutdown Hook is not well-known. You can use something like this.

This feature is available since JDK 1.3
Vitaly
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! Very cool! I didn't know about this.
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic