classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Note on PushbackInputStream


From: John Keiser
Subject: Re: Note on PushbackInputStream
Date: 18 Aug 2001 13:35:55 -0400

On 10 Aug 2001 17:25:58 +1200, Bryce McKinlay wrote:
> Tom Tromey wrote:
> 
> >Suppose a thread calls PushbackInputStream.read and there are no bytes
> >to be read.  So the thread blocks.
> >
> >Now suppose another thread calls PushbackInputStream.unread.
> >
> >Ideally you'd expect the first thread to wake up and read the
> >pushed-back bytes.  However, this doesn't happen.  And in fact it
> >isn't easy to make it happen.  I think you could do it by making a new
> >thread inside PushbackInputStream.read.  That is awfully heavy though.
> >
> In general, I dont think its useful/safe to have more than one thread 
> reading from any given InputStream, so in practise this probibly isnt a 
> problem. Besides, even if there was a way to unblock another reading 
> thread, there would still be consistency issues. If thread A reads a 
> chunk of data, then thread B reads a chunk, then thread A decides to 
> push back a byte, that byte would no longer be in the correct position 
> on the stream.
> 

He's not talking about two threads reading one input stream.  He's
talking about the (probably common) situation where one thread is
reading the input stream and another is writing to it.  I think this is
a reasonable application for PushbackInputStream.

I can't see a way out of the situation either, without creating some
kind of dual block (block on *either* the pushback or the underlying
stream) or possibly setting a time interval to periodically come back
from the underlying stream and check the pushback.

--John





reply via email to

[Prev in Thread] Current Thread [Next in Thread]