Why doesn't more Java code use PipedInputStream / PipedOutputStream?

前端 未结 9 2153
感动是毒
感动是毒 2020-12-02 12:56

I\'ve discovered this idiom recently, and I am wondering if there is something I am missing. I\'ve never seen it used. Nearly all Java code I\'ve worked with in the wild fav

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 13:21

    From the Javadocs:

    Typically, data is read from a PipedInputStream object by one thread and data is written to the corresponding PipedOutputStream by some other thread. Attempting to use both objects from a single thread is not recommended, as it may deadlock the thread.

    This may partially explain why it is not more commonly used.

    I'd assume another reason is that many developers do not understand its purpose / benefit.

提交回复
热议问题