Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

NX: (Contractors) server shutdown and file close

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! Very cool! I didn't know about this.
Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic