Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flaws with PipedInputStream/PipedOutputStream

I've seen two answers on SO that claim that the PipedInputStream and PipedOutputStream classes provided by Java are flawed. But they did not elaborate on what was wrong with them. Are they really flawed, and if so in what way? I'm currently writing some code that uses them, so I'd like to know whether I'm taking a wrong turn.

One answer said:

PipedInputStream and PipedOutputStream are broken (with regards to threading). They assume each instance is bound to a particular thread. This is bizarre.

To me that seems neither bizarre nor broken. Perhaps the author also had some other flaws in mind?

Another answer said:

In practice they are best avoided. I've used them once in 13 years and I wish I hadn't.

But that author could not recall what the problem was.


As with all classes, and especially classes used in multiple threads, you will have problems if you misuse them. So I do not consider the unpredictable "write end dead" IOException that PipedInputStream can throw to be a flaw (failing to close() the connected PipedOutputStream is a bug; see the article Whats this? IOException: Write end dead, by Daniel Ferbers, for more information). What other claimed flaws are there?

like image 374
Raedwald Avatar asked Feb 28 '12 14:02

Raedwald


1 Answers

They are not flawed.

As with all classes, and especially classes used in multiple threads, you will have problems if you misuse them. The unpredictable "write end dead" IOException that PipedInputStream can throw is not a flaw (failing to close() the connected PipedOutputStream is a bug; see the article Whats this? IOException: Write end dead, by Daniel Ferbers, for more information).

like image 88
Raedwald Avatar answered Oct 04 '22 20:10

Raedwald