It's not a secret anymore!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Server Shutdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Server Shutdown" Watch "B&S: Server Shutdown" New topic

B&S: Server Shutdown

Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
How have people managed the server shutdown portion? Have people disregarded it, or presumed that just shutting it down would be enough?

Or (if you're using RandomAccessFile) is


SCJP 1.4 (91%)<br />SCJD 1.4 (376/400, 94%)
he qinfeng

Joined: Sep 13, 2003
Posts: 23
I use the following code open the data file:
File f = new File(dbname);
if (f.exists() && f.canRead() && f.canWrite())
db = new RandomAccessFile(f, "rw");

SCJP<br />SCJD(in progress)
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
I did some reading and it looks like "rws" is a little safer. I did notice a slight delay between writing and "commit"s. I think "rws" will help. I haven't been able to see it yet, which is actually bothering me.

But here's the Java documentation from RandomAccessFile:

The <tt>"rws"</tt> and <tt>"rwd"</tt> modes work much like the {@link
java.nio.channels.FileChannel#force(boolean) force(boolean)} method of
the {@link java.nio.channels.FileChannel} class, passing arguments of
<tt>true</tt> and <tt>false</tt>, respectively, except that they always
apply to every I/O operation and are therefore often more efficient. If
the file resides on a local storage device then when an invocation of a
method of this class returns it is guaranteed that all changes made to
the file by that invocation will have been written to that device. This
is useful for ensuring that critical information is not lost in the
event of a system crash. If the file does not reside on a local device
then no such guarantee is made.

<p> The <tt>"rwd"</tt> mode can be used to reduce the number of I/O
operations performed. Using <tt>"rwd"</tt> only requires updates to the
file's content to be written to storage; using <tt>"rws"</tt> requires
updates to both the file's content and its metadata to be written, which
generally requires at least one more low-level I/O operation.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
one way to shutdown the server properly is to unexport the objects first, then you can call system.exit(0);

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
Unexport? I do not understand.
Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi Robert,

You are saying you are going to do another GUI for the program in server mode?

Clivant Yeo
My Personal Website
subject: B&S: Server Shutdown
It's not a secret anymore!