This content has been marked as final. Show 1 reply
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).