[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Note on PushbackInputStream
From: |
Stuart Ballard |
Subject: |
Re: Note on PushbackInputStream |
Date: |
Tue, 21 Aug 2001 13:21:54 -0400 |
John Keiser wrote:
>
> On 21 Aug 2001 13:47:50 +0200, Dalibor Topic wrote:
> > public class WaitingPushbackInputStream extends PushbackInputStream {
> > [...]
> > public int read() throws IOException {
> > synchronized(this) {
> > synchronized(in) {
> > while(0 == available()) {
> > try {
> > wait();
> > }
> > catch (InterruptedException e) {
> > // ignore
> > }
> > }
> >
> > // something is available for reading,
> > // and we've got both locks. this read
> > // should not block at all.
> > return super.read();
> > }
> > }
> > }
> >
> > public void unread(int oneByte) throws IOException {
> > synchronized(this) {
> > notifyAll();
> > super.unread(oneByte);
> > }
> > }
> > }
> That's some nice code. But how could super.unread() ever get called if
> read() is in its loop? They're both synchronized on this.
AIUI, wait() causes all monitors to be temporarily released. So a call
to unread() will go through as soon as read() hits the line that says
wait().
But ICBVW...
Stuart.
- Note on PushbackInputStream, Tom Tromey, 2001/08/06
- Re: Note on PushbackInputStream, Bryce McKinlay, 2001/08/10
- Re: Note on PushbackInputStream, John Keiser, 2001/08/18
- Re: Note on PushbackInputStream, Dalibor Topic, 2001/08/19
- Re: Note on PushbackInputStream, Tom Tromey, 2001/08/20
- Re: Note on PushbackInputStream, Dalibor Topic, 2001/08/21
- Re: Note on PushbackInputStream, John Keiser, 2001/08/21
- Re: Note on PushbackInputStream,
Stuart Ballard <=
- Re: Note on PushbackInputStream, John Keiser, 2001/08/21
- Re: Note on PushbackInputStream, Tom Tromey, 2001/08/21
- Re: Note on PushbackInputStream, Dalibor Topic, 2001/08/22