classpath
[Top][All Lists]
Advanced

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

Re: Note on PushbackInputStream


From: Tom Tromey
Subject: Re: Note on PushbackInputStream
Date: 21 Aug 2001 12:33:27 -0600

>>>>> "Dalibor" == Dalibor Topic <address@hidden> writes:

Dalibor>     public void unread(int oneByte) throws IOException {
Dalibor>        synchronized(this) {
Dalibor>            notifyAll();
Dalibor>            super.unread(oneByte);

I think you want to call super.unread() before notifyAll().

Dalibor> this solution avoids polling, and only reads when there is
Dalibor> something available for reading. It relies on being notified
Dalibor> that there is something available.

Yes.  It is possible to do this.  However, there is an additional
constraint you're ignoring, which is that PushbackInputStream must
rely only on the API presented by InputStream.  That is why this bug
is inherent in the design -- you can't do it without either extending
the API (not allowed) or introducing a new thread (hugely expensive).

Dalibor> That's right, but isn't it considered as "good practice" in
Dalibor> continuous/polling loops ?

Yes.

Tom



reply via email to

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