Name: gm110360 Date: 10/12/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
uname -a
Linux <HOSTNAME> 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i686 unknown
Thread.interrupt doesn't work for InputStream.read(). This is related to bug
#4344135, but doesn't involve closing of an underlying socket.
The program below shows that the thread cannot be interrupted.
The program works fine under Solaris 8 Update 5 with JDK 1.3.1.
import java.net.*;
/** Tests Thread.interrupt() against InputStream.read() */
public class test2 {
static class SleeperThread extends Thread {
public void run() {
int c;
try {
c=System.in.read();
}
catch(Exception ex) {
System.err.println("test2.SleeperThread.run(): " + ex);
}
}
}
public static void main(String[] args) {
Thread thread;
final long TIMEOUT=3000;
thread=new SleeperThread();
thread.start();
System.out.println("test2.main(): sleeping for " + TIMEOUT + " msecs");
try {thread.sleep(TIMEOUT);} catch(Exception e) {}
System.out.println("test2.main(): sleeping -- done");
System.out.println("test2.main(): interrupting thread");
thread.interrupt();
System.out.println("test2.main(): interrupting thread -- done");
System.out.println("test2.main(): joining thread (timeout=" + TIMEOUT + "
msecs)");
try {thread.join(TIMEOUT);} catch(Exception e) {}
System.out.println("test2.main(): joining thread -- done");
System.out.println("test2.main(): thread.isAlive()=" + thread.isAlive());
if(thread.isAlive()) {
System.out.println("test2.main(): thread was interrupted but is still
running !");
}
}
}
(Review ID: 133623)
======================================================================