gpt4 book ai didi

java - PipedInputStream/PipedOutputStream 的缺陷

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:37:35 29 4
gpt4 key购买 nike

我在 SO 上看到了两个答案,它们声称 Java 提供的 PipedInputStreamPipedOutputStream 类存在缺陷。但他们没有详细说明他们出了什么问题。他们真的有缺陷吗?如果有的话是什么?我目前正在编写一些使用它们的代码,所以我想知道我是否走错了路。

One answer说:

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

对我来说,这既不奇怪也不坏。也许作者还有其他一些缺陷?

Another answer说:

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

但是那个作者想不起来是什么问题了。


对于所有类,尤其是在多线程中使用的类,如果误用它们就会出现问题。所以我不考虑不可预知的"write end dead" IOException PipedInputStream 可能会抛出一个缺陷(未能 close() 连接的 PipedOutputStream 是一个错误;请参阅文章 Whats this? IOException: Write end dead,作者: Daniel Ferbers,了解更多信息)。还有哪些其他声称的缺陷?

最佳答案

它们没有缺陷。

对于所有类,尤其是在多线程中使用的类,如果误用它们就会出现问题。 PipedInputStream 可能抛出的不可预测的“写入结束死机”IOException 不是缺陷(无法close() 连接的PipedOutputStream 是一个错误;有关更多信息,请参阅 Daniel Ferbers 的文章 Whats this? IOException: Write end dead

关于java - PipedInputStream/PipedOutputStream 的缺陷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9483833/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com