FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux foo.bar.com 2.4.22 #10 Fri Oct 31 14:12:30 CST 2003 i686 i686 i386 GNU/Linux
Also occurs on FreeBSD and Windows.
A DESCRIPTION OF THE PROBLEM :
The API spec for Thread.sleep(long) and Thread.sleep(long, int) claims
that it throws InterruptedException "if another thread has interrupted the current thread".
First, this sentence is misleading, as a thread can interrupt itself. So it
should read "if any thread has interrupted the current thread."
Secondly, the implemetation fails according to this specification.
If Thread.sleep(0) or Thread.sleep(0,0) is invoked, InterruptedException
is *never* thrown, even if the thread has been interrupted.
Please either fix this bug or "fix" the spec (as Sun often prefers to do).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run this program:
public class zz {
public static void main(String[] args) throws Exception {
Thread.currentThread().interrupt();
Thread.sleep(0, 0);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
InterruptedException thrown
ACTUAL -
No exception thrown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class zz {
public static void main(String[] args) throws Exception {
Thread.currentThread().interrupt();
Thread.sleep(0, 0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Invoke Thread.sleep(1) instead.
###@###.### 2004-12-31 05:59:16 GMT