Write end dead exception occurs in the following situation: Two threads:
A: PipedOutputStream put = new PipedOutputStream();
   String msg = "MESSAGE";
   output.wirte(msg.getBytes());
   output.flush();
B: PipedInputStream get = new PipedOutputStream(A.put);  
   byte[] get_msg = new byte[1024];
   get.read(get_msg);
Here is the situation: A and B run concurrently, and A writes to the pipe and B reads it. B just read from the pipe and buffer of this pipe is cleared. Then A doesn't write msg to the pipe in unknown interval. However, at one moment, B read the pipe again and java.io.IOException: write end dead occurs, because the buffer of the pipe is still empty. And I don't want to sleep() thread B to wait for A writing the pipe, which is also unstable. How to avoid this problem and solve it? Thanks