Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Server Shutdown

 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

enough?
 
he qinfeng
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one way to shutdown the server properly is to unexport the objects first, then you can call system.exit(0);
 
Robert Konigsberg
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unexport? I do not understand.
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,

You are saying you are going to do another GUI for the program in server mode?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic