aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Closing the database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Closing the database." Watch "Closing the database." New topic
Author

Closing the database.

Nagendra Nune
Greenhorn

Joined: Feb 09, 2004
Posts: 7
This may be a silly question but I need help.
When the client is connected locally, it closes the database (a random access file) when it exits. That is fine.
But when the client is connected to a database on the network server, what is the appropriate way to close it. A client cannot close it since another client may be accessing it. So, I assume it is a responsibility of the database server. Since we run the server in a DOS window, we close it by either closing the DOS window or by terminating the session by using CTRL + C. In this case, how do I know this event and close the database?
Or do I even care to close the database in case of a network server?
Please help.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Nagendra,
Originally posted by Nagendra Nune:
Since we run the server in a DOS window, we close it by either closing the DOS window or by terminating the session by using CTRL + C. In this case, how do I know this event and close the database?
Or do I even care to close the database in case of a network server?
Please help.

If you don't have a GUI for your server how do you allow the user to specify the location of the database or pick the port over which the server connects to the network? If you did have a server GUI then you could close the database when the user exits the GUI.
Hope this helps,
George


Regards, George
SCJP, SCJD, SCWCD, SCBCD
Nagendra Nune
Greenhorn

Joined: Feb 09, 2004
Posts: 7
George,
Thanks for the reply. I use command-line arguments to specify database path and the port for the RMI Server. I am just curious to know what other people did in this case.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Nagendra,
You might find that you have something like the following in your assignment instructions:

When you submit your assignment, each part (client and server) must be executable using a command of this exact form:
java -jar <path_and_filename> [<mode>]
Your programs must not require use of command line arguments other than the single mode flag, which must be supported. Your programs must not require use of command line property specifications. All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.
The mode flag must be either "server", indicating the server program must run, "alone", indicating standalone mode, or left out entirely, in which case the network client and gui must run.
You must not require manual editing of any files by the examiners.

If you have the same statement in your assignment instructions then I would say you are prohibited from using command-line arguments (except for the authorized mode flag).
The alternative is for the executable to have a GUI regardless of the operating mode. The GUI allows the user to specify configuration parameters (like location of database file, for instance) that are needed in a particular operating mode. These configuration parameters are persisted in the suncertify.properties file so that they can be reused by the next run of the executable.
Hope this helps,
George
Yanick Labelle
Ranch Hand

Joined: Dec 29, 2003
Posts: 50
Hi, my question is not about closing the data file or not. I close it.
My question is about: What do you do on the server with the threads that are currently processing client request when the server is to be closed?
It could leave the database in an inconsistent state (in de middle of a create or update operation..., with half of the record updated or created)
my server has:
A window (main thread of execution)
A NetworkServer (started as a thread when the server app. starts)
NetworkServerThread (Started by NetworkServer to process a request)
NetworkServerThread (Started by NetworkServer to process a request)
NetworkServerThread (Started by NetworkServer to process a request)
NetworkServerThread (Started by NetworkServer to process a request)
NetworkServerThread (Started by NetworkServer to process a request)
NetworkServerThread (Started by NetworkServer to process a request)
I was thinking about keeping a list of the NetworkServerTread that are currently running. Access to this list is to be synchronized...
When the user asks for the server to stop, I do networkServer.interrupt()
to stop the NetworkServer from spawning new NetworkServerThread(s)... And scan the list of NetworkServerThread, doing thread1.join(), thread.join(), etc...
This way, the server will terminate, but not before all the tasks already started are finished...
What do you think? Is it too much for the assignment?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing the database.