The following program works fine in 1.3 and 1.4 but does not terminate in Tiger/Mustang: === import java.io.*; public class PipeTest { public static void main(String args[]) throws Exception { Thread t = null; try { PipedInputStream in = new PipedInputStream(); final OutputStream out = new PipedOutputStream(in); t = new Thread("WriterThread") { public void run() { try { System.out.println("Writer started."); out.write(new byte[64*1024]); } catch( Throwable e ) { System.out.println("Writer exception:"); e.printStackTrace(); } finally { System.out.println("Writer done."); } } }; t.start(); System.out.println("Reader reading..."); in.read(new byte[2048]); System.out.println("Reader closing stream..."); in.close(); System.out.println("Reader sleeping 3 seconds..."); Thread.sleep(3000); } catch( Throwable e ) { System.out.println("Reader exception:"); e.printStackTrace(); } finally { System.out.println("Reader done."); System.out.println("Active threads:"); Thread[] threads = new Thread[Thread.activeCount()]; Thread.enumerate(threads); for( int i=0; i<threads.length; i++ ) { System.out.println(" " + threads[i]); } System.out.println("Waiting for writer..."); t.join(); System.out.println("Done."); } } } === The expected behavior is that the call to in.close() by the reader awakes the writer (making it throw an "java.io.IOException: Pipe closed"). However, the writer remains blocked forever unless the reader Thread terminates. The cause would seem to be in PipedInputStream.awaitSpace(), which only checks if the Thread doing the read is alive but not if the Pipe has been closed. That code was modified in Tiger by the fix for 4882082. ###@###.### 2005-1-20 21:39:52 GMT
|