java.lang/77: sleep(0) sleeps forever
Sun Oct 24 03:16:00 GMT 1999

>Number:         77
>Category:       java.lang
>Synopsis:       sleep(0) sleeps forever
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tromey
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 24 03:16:00 PDT 1999
>Originator:     Mike Moreton
>Release:        libgcj-2.95.1
Linux, posix threads
If you run the progam attached in the "How-to-repeat"
section, the behavious is different under the Sun JDK and

Under Sun JDK 1.2.1, it's clear that sleep(0) means "sleep
for a very short time", while with libgcj the thread sleeps
until interrupted.

public class TestSleep{
        public static void main(String[] args) {
                (new Doit()).start();

class Doit extends Thread{
        public synchronized void run() {
                for (int i = 0; i < 10; i++) {
                        System.out.println("i is now "+i);
                        try {
                                if (i==5) {
                                } else {
                        } catch (InterruptedException e) {}
In, in method java::lang::Thread::sleep (jlong millis, jint nanos)
add at the start of the method the following code

  if ((millis == 0) && (nanos == 0)) {

More information about the Java-prs mailing list