File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Simply server shutdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Simply server shutdown" Watch "Simply server shutdown" New topic
Author

Simply server shutdown

Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

Hi all,

in this forum there are many ideas about a correct server-shutdown, and I think, most of them are all over-engineering for the SCJD-assignment. There are long discussions about complete database-locking and timeouts, but is this really necessary? I agree that in the real world a sophisticated server-shutdown is appropriate, but there is no requirement to do so in the SCJD-assignment. What do you think about the following: When the user clicks on the "Shutdown"-button in the server-GUI, the server only closes the RAF-File and then exits the program with System.exit(). Could I be penalized for this simple server shutdown, or is it highly recommended to develop a complex server-shutdown for my URLyBird?

Regards

Oliver
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
The important thing is to consider if you might actually NEED a shutdown operation based upon your solution. For me, it depended upon the nature of my I/O operations.

In my particular solution, even though my database access is thread-safe, a shutdown mechanism helps ensure that you don't accidentally perform a half-write before pressing CTRL-C (or typing 'kill', or whatever).


SCJP 1.4 (91%)<br />SCJD 1.4 (376/400, 94%)
Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

I think in every SCJD-assignment and every design exists the problem to perform a half-write during server-shutdown. But in the newer assignments there are no requirements to implement a complete server shutdown with database-locking. In the thread "Shutdown Server Properly" some ranchers discussed a complex server shutdown-scenario, and Mark Spritzler wrote:


You guys are going way overboard. I have been here at JavaRanch in this forum for over three years now, most of them as the bartender, and this has got to be the most stubborn group of programmers I have seen so far. Get over it, and realize that if Sun wanted you to go this far, they would be charging a lot more than $250. They want a simple straight-forward solution that still tests skills. Going overboard like this is not going to gain extra points, but can cause you to lose points. I have seen this over and over again. After you get your score, you will come back and say, I guess I went to far.


Since I have read this I don't want to implement too much to close my server. Or is it really necessary to check that there are no activ clients on my server before I start the shutdown?
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
I wish I saw that before I wrote my solution!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Oliver,

Your simple solution at the start of this thread sounds nearly perfect to me. You do have to be aware that multiple threads can be running, so you may want to have your block of code which closes the database file synchronized on the same object that your update() method synchronizes on - that way there should not be any writes in progress.

Technically a blocked update() call could start running between when you close the data file and when you call System.exit(), and will therefore throw some exceptions - I will leave it to you to think about whether you need to handle this or not.

It is always good to be reminded to keep the solutions simple, and that was something that Mark brought up time and time again. The new assignment instructions even have a statement to say that you will not get extra marks for going beyond the specification.

There are some of us in this forum (myself included) who like to follow any path to see where it leads us. There are many subjects raised in here that I have talked about at great length (which may make people think that I am advocating that design) when it is not something that I would do in my solution. My solution was a lot simpler than many of the solutions I have seen here.

So to reitterate: Try and keep your solutions simple!

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

Hi Andrew,

your supplementation of my server shutdown sounds great. I think, it is a good idea to put the file-closing in synchronized code.

Thank you very much for your help!

Regards,

Oliver
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simply server shutdown
 
Similar Threads
Problem(?) in Andrew's Denny Dvd setDatabaseLocked() method
How to prepare?
Questions regarding Safe Server Shutdown
Server shutdown
Question about CleanExit in Andrew's "Dennys DVDs"