Name: el35337 Date: 06/24/97
The following Daemon.java program:
----------------------------------------------------------------
import java.io.*;
public
class Daemon
{
public static
void
main(String[] args)
{
PrintStream out = System.out;
out.print("main: Starting read thread...");
out.flush();
new Thread(new Reader(), "Reader").start();
out.println("done.");
out.println("main: Calling yield(). Note: Reader thread should block in
");
out.println(" FileInputStream.read() call, so our thread should con
tinue...");
Thread.yield();
out.println("main: Now we are continuing...");
}
};
class Reader
implements Runnable
{
public
void
run()
{
PrintStream out = System.out;
try {
out.println("reader: Reading one byte...");
new FileInputStream(FileDescriptor.in).read();
out.println("reader: Read one byte.");
}
catch (IOException e) {
e.printStackTrace();
}
}
};
----------------------------------------------------------------
when run using the following cmdline:
{ echo "Press ENTER to send one byte:" >&2; read; echo -n s; }|java Daemon
issues the following output:
----------------------------------------------------------------
Press ENTER to send one byte:
main: Starting read thread...done.
main: Calling yield(). Note: Reader thread should block in
FileInputStream.read() call, so our thread should continue...
reader: Reading one byte...
reader: Read one byte.
main: Now we are continuing...
----------------------------------------------------------------
company - InterSoft Argentina S.A. , email - ###@###.###
======================================================================
- duplicates
-
JDK-1237893 Solaris: block on read of System.in blocks all threads
- Closed