I was wresting with this too. I wanted to be sure to get a global lock and shut down the Data class safely. I accomplished it by making a very simple Server GUI. It displays messages about what the server is doing and has a "Stop FBN Server" button. That button locks the DB and shuts down cleanly. No nasty Ctrl-c shutdown while a client is modifying a record.
I agree that you can run the server with a nice GUI, which allows the user to monitor the execution and everything, but I personally dislike the approach. I believe that a server should be a command-line based utility that can be kept running in "background" (if your OS supports this), and should be shut down in a clean way. I implemented graceful shutdown using RMI. My server binds a DatabaseService object to a RMI Registry. When this object receives a remote invocation of the shutdown() method, all open client connections, which are also Remote objects bound to the registry are unexported (forced). Finally, the DatabaseService is also unexported. As the RMI registry contains no more objects, the thread managing RMI finishes, and the server stops executing. By the way, the call to shut down the server (in my case) is something like: java -Dsuncertify.port="4444" suncertify.server.Server -s where the -s switch implies a shutdown, and the previous defined property is the port on the local machine (obvious) that the server is running on. This means that YOU CAN ONLY SHUT DOWN A SERVER RUNNING ON THE SAME MACHINE, NOT A REMOTE ONE (eventhough you apply RMI to achieve this)... Hope this helps... Benjam�n
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!