I don't think any of these solutions help, as I did not write the
writer thread and cannot alter its code.

Unless I am missing something, use of notify/wait would only move the
sleep() to another thread, achieving nothing.

Is there no intrinsic, system-based means of having a read block until
the stream is closed (rather than having just temporarily run dry) or
has more data to offer?  This is a key part of many I/O systems, yes?

tone


On Dec 19, 9:22 am, Kostya Vasilyev <[email protected]> wrote:
> Use Java thread synchronization:
>
> http://www.javamex.com/tutorials/synchronization_wait_notify.shtml
>
> Have the reader thread "wait" when there is no data and the writer
> thread "notify" the reader when more data is available (and when it
> should exit its processing loop).
>
> -- Kostya
>
> 19.12.2010 16:38, DulcetTone пишет:
>
>
>
>
>
>
>
>
>
> > I have code in a worker thread that needs to efficiently read a
> > constantly-growing input stream from a process.
>
> > The issue is that the present design uses a sleep() for a short period
> > if there is no input presently available, and I'd like the attempt to
> > read the input stream simply *block* so it magically awakes when more
> > input is available.  I fear this will mean a small hit on phone
> > responsiveness.
>
> > How does one alter code from this form to do such a thing?
>
> > BufferedReader bufferedReader =
> >                  new BufferedReader(new
> > InputStreamReader(process.getInputStream()));
>
> >              do {
> >                  String line;
> >                  while ((line = bufferedReader.readLine()) != null) {
> > // new input would be processed here
> >                  }
> >                  Thread.sleep(500); // TODO: make this go away
> >              } while (true);
>
> --
> Kostya Vasilyev -- WiFi Manager + pretty widget 
> --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to