[concurrency-interest] Contract of java.io.OutputStream.write(byte b)
gregg at cytetech.com
Wed May 31 22:47:51 EDT 2006
Bill Pugh wrote:
> If you have two different threads trying to push bytes into an output
> stream, I'm hard pressed to
> imagine situations in which allowing the threads to non-
> deterministically interleave is a good idea.
A logging stream is one place where letting the writes happen in any order is
probably okay. You do want the entire byte to go out in one piece, so
synchronizing on the write call is an easy way to do this.
I've counted on the synchronized OutputStream behavior in more than one place,
without second thought that its presense in an API's Javadoc doesn't necessarily
make it a requirement of all implementations extending or using that API.
More information about the Concurrency-interest