Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Can a file be written to in different, non-overlapping places? Will that corrupt a file?
SCJP 1.4, SCJD
Originally posted by Anton Golovin:
[ August 03, 2004: Message edited by: Anton Golovin ]
Originally posted by mike acre:
In reply to Anton
As I see it, every method that reads or writes to the file must be synchronised.
A method moves the pointer then reads or writes from that point. This must be guaranteed as one atomic operation. As such synchronising the methods in your file access object does the job perfectly.
So no, you can't have two threads concurrently writing in different, non-overlapping places. They must be queued with the aid of the objects monitor.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
A method moves the pointer then reads or writes from that point. This must be guaranteed as one atomic operation. As such synchronising the methods in your file access object does the job perfectly.
So no, you can't have two threads concurrently writing in different, non-overlapping places. They must be queued with the aid of the objects monitor.
Raj Nagappan<br />SCJP, SCJD, PhD
Suppose the thread A is reading/updating record 1. Can other threads read/update record 2 at the same time?
SCJP 1.4 (91%)<br />SCJD 1.4 (376/400, 94%)
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|