Forums Register Login

NX: about updataRecord

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
What's wrong? Where are you going? Stop! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 776 times.
Similar Threads
FileChannel and read method
NX:Using RandomAccessFile and FileChannel
NX: (HTL) FileChannel & Threads
NX: (Contractors) File I/O class
NX: FileChannel & ThreadSafety
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:46:29.