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?
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).
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?
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!