Problematic implementation of java.io.DataInputStream ?

Mark Wielaard mark@klomp.org
Tue May 20 07:58:00 GMT 2003


Hi,

On Mon, 2003-05-19 at 12:19, Michael Koch wrote:
> the class java.io.DataInputStream uses a little buffer called "buf" to 
> make primitive read calls more efficient.
> 
> The problem is that when two different threads call methods using this 
> buffer the buffer may contain wrong data when one thread is 
> interrupted between filling of the buffer and conversion of the 
> primitive data type.

You could synchronize all methods that use the private byte buffer like
the Classpath code seems to do. But the behaviour of IO streams is
non-deterministic when multiple threads use the same stream without
using some kind of lock anyway. So I don't think we should worry about
it.

Cheers,

Mark



More information about the Java mailing list