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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: about updataRecord" Watch "NX: about updataRecord" New topic
Author

NX: about updataRecord

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi,
I am using nio, and using a RandomAccessFile to get a FileChannel, and mapped the data section of database into buffer using the FileChannel. I updata the data successfully, my question is when to force() the buffer? In addition, I found even if I didn't use force() method, after I closed the channel and randomaccessfile, the data was writen to harddisk automatically. why?
I think all the data should be force() only once, before the shut off of server. During the running period of server, all the operation is on the buffer.
need your comment, thank you.
Regards,
Damu
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Hi damu,

I think all the data should be force() only once, before the shut off of server. During the running period of server, all the operation is on the buffer.
need your comment, thank you.

If you works on the buffer all the time without writing immediately, maybe some important data will lose when the server crashes or power failure occurs. That may happen. How will you handle it?
Regards.
Rick


SCJD 1.4
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi thank you,
Yes it is a problem, then how do you think to force() every time updata or delete a record? The data can be writen to disk immediately.
regards
Damu
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Hello,
I have no much experience on NIO because I only use RAF. Maybe you should check the force() method. But I noticed one thing:

This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class. It may or may not force changes that were made by modifying the content of a mapped byte buffer obtained by invoking the map method. Invoking the force method of the mapped byte buffer will force changes made to the buffer's content to be written.

Rick
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi Rick ,
You wrote:
If you works on the buffer all the time without writing immediately, maybe some important data will lose when the server crashes or power failure occurs. That may happen. How will you handle it?

I decide to change my solution: Don't save the buffer whenever a change happened, save it at last when the server is shut down. And buy a UPS, a good anti-virus software. Is that sound cool?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: about updataRecord
 
Similar Threads
NX: FileChannel & ThreadSafety
NX:Using RandomAccessFile and FileChannel
NX: (Contractors) File I/O class
FileChannel and read method
NX: (HTL) FileChannel & Threads