Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Graceful Server Shutdown

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I am looking at how to address Server Shutdown. As I see it for this scenario, I need to :-
1) ensure all writes to the DB have completed
2) close the DB file

However, I am not sure whether to remove the service from the RMI register, as the client will get the exception of service not available.

I have a server GUI which provides an "Exit" button to stop the server. My approach is to use the addShutdownHook. I have defined an inner class, ServerShutdown, in
my Data class which uses a private Data class method processServerShutDown (). All the Data class members are synchronized, therefore, when the processServerShutDown () is invoked, it will have exclusive access to Data class members. I have a map of all the locked records ( lockedRecords ).


Below is a bit of test code I used :


Below is the output from the client side run.

Below is the output from the server side run.

It seems that the processServerShutDown() is working fine in that it waits for writes to the DB to be completed, before closing the DB file and completing. However, I had assumed that at this point the server service and effectively access to the Data class to a client would be availble because the JVM would terminated the server process. But from the above log, there is still a window after the processServerShutDown() has completed that server service is STILL available. My concern is that in this window, it is possible for a client to get half way through a Booking and the server terminates leaving a a client in wait for the Book to complete but will not and a corrupted DB file.

Any suggestions as to how I can stop any further access to the Data class by a client after the processServerShutDown() ?

I could introduce a static flag which could be monitored at the start of every method in the Data class but. I just wondered if there is a neater approach !

Of course, please feel free to improve/correct me if you see an issue in the above.

Regards

Pete


 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want to check this thread out about server shutdown
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi K,

Looked at that thread earliar and definitely the correct one for this subject. Thanks

Regards

Pete


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic