United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6213203 : (thread) Thread.sleep(0) fails to detect interrrupted status

Details
Type:
Bug
Submit Date:
2004-12-31
Status:
Closed
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2005-09-22
Component:
hotspot
OS:
linux,windows_xp
Sub-Component:
runtime
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2,6
Fixed Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

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



Hardware and Software, Engineered to Work Together