多线程管道通信 PipedInputStream抛出IOException "write end dead"异常 怎么解决?在线等
想在Thread A中,利用PipedOutputStream写入数据
在Thread B中,循环读取数据
只要 Thread A写数据了,线程B就读
Thread A
负责接收user 输入
并用 管道 ,将 数据发送给 Thread B
Thread B
读取Thread A传来的数据
while(true)
{
byte[] bytes = new byte[100];
int bytesLength=input.read(bytes);//这里第2次会抛出异常..
String srcStr=new String(bytes,0,bytesLength);
}
可在 Thread B中,
循环第1次 能够正确读取信息
循环第2次 抛出了 IOException
并且提示
write end dead
不知道什么原因?
[解决办法]
if (writeSide != null && !writeSide.isAlive()&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}