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

NX: about updataRecord

 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic