FileInputStream and FileOutputStream to the same file: Is a read() guaranteed to see all write()s that "happened before"?
Posted
by
user946850
on Stack Overflow
See other posts from Stack Overflow
or by user946850
Published on 2012-10-05T07:54:33Z
Indexed on
2012/10/07
21:37 UTC
Read the original article
Hit count: 193
I am using a file as a cache for big data. One thread writes to it sequentially, another thread reads it sequentially.
Can I be sure that all data that has been written (by write()
) in one thread can be read()
from another thread, assuming a proper "happens-before" relationship in terms of the Java memory model? Is this behavior documented?
EDIT: In my JDK, FileOutputSream
does not override flush()
, and OutputStream.flush()
is empty. That's why I'm wondering...
EDIT^2: The streams in question are owned exclusively by a class that I have full control of. Each stream is guaranteed to be accesses by one thread only. My tests show that it works as expected, but I'm still wondering if this is guaranteed and documented.
See also this related discussion: http://chat.stackoverflow.com/rooms/17598/discussion-between-hussain-al-mutawa-and-user946850
© Stack Overflow or respective owner