1 Reply Latest reply: Jan 27, 2009 7:22 PM by 807557 RSS

    Pipe in real time

      Hi David,
      we want to know:
      is there any problem to not use pipes (PipedInputStream PipedOutputStream PipedReader PipedWriter)
      in real time environment.

        • 1. Re: Pipe in real time
          None of the standard Java libraries were designed for real-time use. How effective using Pipes will be depends on how you want to use them. Internally these classes use synchronized methods (good) plus wait/notify (bad). The use of wait/notify has two problems:

          a) in general if the waiter and the notifier are different priorities then you can get a priority inversion. A high priority thread could be waiting for a low-priority thread to pass some data, but a medium priority thread prevents the low-priority thread from running.

          b) In particular this code always does the wait with a 1 second timeout, so if the communication rates are low then threads waiting for data will wake up once a second check for more data and go back to waiting. Similarly if a producer outpaces a consumer then the producer blocks waiting for space to write, but wakes up once a second to see if there is space. This will introduce jitter and related non-determinism.

          You can deal with (a) by using a single thread at each end of the pipe with the same priorities. But you can't do anything about (b).

          David Holmes