-
Bug
-
Resolution: Not an Issue
-
P5
-
None
-
1.3.0
-
x86
-
linux
Name: boT120536 Date: 01/21/2001
'uname -a':
Linux flanger 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown
'java -version':
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
The following source registers a signal handler to trap SIGINT. Upon reception
of SIGINT, thread main is interrupted from it's sleep state. After catching
'InterruptedException', another sleep() is attempted. The erroneous behavior is
that the second sleep() immediately throws 'InterruptedException' when in fact
the interrupt() should have cleared thread main's interrupted state. The
expected behavior is witnessed on a Sun Solaris machine with jdk v1.2.2-05a
(i.e., the second sleep() completes successfully).
Source
-------
import sun.misc.Signal;
import sun.misc.SignalHandler;
public class SleepInterruptTest {
public static void main (String[] args) {
// Installs Ctrl-C handler...
final Thread thread = Thread.currentThread();
SignalHandler old = null;
try {
old = Signal.handle(
new Signal("INT"),
new SignalHandler() { public void handle(Signal sig) {
thread.interrupt(); } }
);
} catch (IllegalArgumentException e) {
System.out.println("Could not register signal handler.");
e.printStackTrace();
System.exit(-1);
}
try {
System.out.println("About to sleep 10 seconds for the first
time...");
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
try {
System.out.println("\nAbout to sleep 10 seconds for the second
time...");
Thread.sleep(10000);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Results:
--------
About to sleep 10 seconds for the first time...
[Send SIGINT via 'Ctrl-C'...]
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at SleepInterruptTest.main(SleepInterruptTest.java:24)
About to sleep 10 seconds for the second time...
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at SleepInterruptTest.main(SleepInterruptTest.java:29)
(Review ID: 115328)
======================================================================