JDK-6213203 : (thread) Thread.sleep(0) fails to detect interrrupted status
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.2,6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_xp
  • CPU: x86
  • Submitted: 2004-12-31
  • Updated: 2012-10-08
  • Resolved: 2005-09-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b53Fixed
Related Reports
Duplicate :  
Relates :  
Description
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

Comments
EVALUATION The @throws/@exception doc defect about "another thread" mentioned in the description has been accepted as library doc CR 6311092.
2005-08-15