Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem of using Pipe in threads  RSS feed

 
Wes Yuen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have encountered a "java.io.IOException: Write end dead" in the
following code:



From my observation, whenever the timer thread is killed the pipe will be
automatically broken. What's the cause of this exception?
I ran the above code on java version "1.5.0_06" and Windows XP home sp2.
Thanks in advance.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if your problem is the same as the one I had with PipedReader/Writer, but it might be, so I'll share it.

The documentation doesn't say so, but UTSL reveals that PipedReader/Writer expect exactly one thread to do the reading and one thread to do the writing. If one of those threads dies, it considers the pipe broken.

So, you can't do what I tried to do. I had a PipedReader open on one thread, connected to a PipedWriter. I tried to write snippets to the PipedWriter from various threads. But when the first writing thread died, so did my PipedReader/Writer.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never used PipedReader / PipedWriter, but for PipedInputStream / PipedOutputStream, it seems to keep track of only the last thread that read or write to the pipe. So...

When I got an IOException, due to a thread death on the other side of the pipe, I just waited until another thread used the other side of the pipe, and tried again. This worked because my threads rarely died, it only happened when the application changed users.

Henry
 
Wes Yuen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.
Now i try to prevent killing the timer thread before the main thread using the pipe.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!