MappedByteBuffer force does not write to disk

V

vissuyk

Hi All,

I have been playing with MappedByteBuffer and file channels (NIO). I
have been to read a FileInputStream succesfully. When I then update
(using mappedbytebuffer.put(byte[]), it does write the update to disk.
Next time I restart the Java program and perform the read, it does not
have the update.

I did mappedbytebuffer.close but that did not help. Any tips are
appreciated. JDk = 1.5, OS = Linux 32 bit RHAT

Thanks

Vissu
 
V

vissuyk

BTW, I have been able to read the updated date in memroy. When the
program terminated and retstarted the update is not seen which means
it was not persistent. I was under the assumption that when using
mapped byte buffer the OS automatically propagates the writes to disk.

I opened RandomAccessFile() in rw mode, then obtained filechannel from
it, then got hold of MappedByteBuffer by maping the length of the
file.
 
E

Esmond Pitt

I have been playing with MappedByteBuffer and file channels (NIO). I
have been to read a FileInputStream succesfully. When I then update
(using mappedbytebuffer.put(byte[]), it does write the update to disk.

Next time I restart the Java program and perform the read, it does not
have the update.

I don't understand. These two statements are mutually contradictory. If
the update went to the disk, it would have been there next run. Is there
a 'not' missing somewhere.
 
V

vissuyk

I have been playing with MappedByteBuffer and file channels (NIO). I
have been to read a FileInputStream succesfully. When I then update
(using mappedbytebuffer.put(byte[]), it does write the update to disk.
Next time I restart the Java program and perform the read, it does not
have the update.

I don't understand. These two statements are mutually contradictory. If
the update went to the disk, it would have been there next run. Is there
a 'not' missing somewhere.


OOPS, the updates DID NOT make it to the disk. However, once updated,
the updated values can be read from memory location.
 
E

Esmond Pitt

OOPS, the updates DID NOT make it to the disk. However, once updated,
the updated values can be read from memory location.

Of course. So you're saying you called MappedByteBuffer.force() and
nothing happened to the disk? and no exception was thrown?
 
V

vissuyk

Of course. So you're saying you called MappedByteBuffer.force() and
nothing happened to the disk? and no exception was thrown?

Thats' right. Called force, then program terminates. Another program
starts and accesses the file and it sees old content - not the updated
content.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top