/**
* @tests java.io.PipedWriter#write(int)
*/
public void test_write_I_MultiThread() throws IOException {
final PipedReader pr = new PipedReader();
final PipedWriter pw = new PipedWriter();
// test if writer recognizes dead reader
pr.connect(pw);
class WriteRunnable implements Runnable {
boolean pass = false;
volatile boolean readerAlive = true;
public void run() {
try {
pw.write(1);
while (readerAlive) {
// wait the reader thread dead
}
try {
// should throw exception since reader thread
// is now dead
pw.write(1);
} catch (IOException e) {
pass = true;
}
} catch (IOException e) {
//ignore
}
}
}
WriteRunnable writeRunnable = new WriteRunnable();
Thread writeThread = new Thread(writeRunnable);
class ReadRunnable implements Runnable {
boolean pass;
public void run() {
try {
pr.read();
pass = true;
} catch (IOException e) {
//ignore
}
}