JDK-4373068 : Thread.sleep() does not work as expected in Solaris.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.2.2,1.4.2
  • Priority: P1
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux,solaris_8
  • CPU: x86,sparc
  • Submitted: 2000-09-21
  • Updated: 2000-10-19
  • Resolved: 2000-10-19
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The sleep function does not accuratly block for the specified
milliseconds. 

please try the program listed below :

*********** timeTest.java ****************

class timeTest
{

        public static void main(String[] args)
        {

                long start = System.currentTimeMillis();

                for(int i = 0;i < 1000;i++) {

                        try {
                        Thread.sleep(1);
                        } catch( InterruptedException ex) {}
                }

                long stop = System.currentTimeMillis();

                System.out.println(" Time taken : " + (stop - start));
        }
}

**********************************************

on running this program in Solaris 8 & Solaris 7 with jdk1.2.2 

the program prints a result of 19992 milliseconds.

on windows NT, I get the correct expected result of 1002 milliseconds. 

I get varying results with other JDK's ( with 1.3 it took 10003 ms)
in Solaris. 

clearly the sleep function is broken for the solaris environment
as it does not block accuratly for the specified time. 

balaji.raghunathan@eng 2000-09-21

Thread.sleep() for nano seconds time interval does not work too. 

Thread.sleep() simply does not timeout properly for any given
time interval. This could be a very serious problem in all Java
based server software for the Solaris platform.  note: it works ok in 
Windows NT and that makes this bug even more important to fix. 





Comments
EVALUATION Thread.sleep() does not guarantee arbitrarily small time quantum accuracy. The correct behavior in the face of sleep() invocations with quantum smaller than what the underlying implementation can support is not defined. The Solaris JDK 1.2.2 implementation uses a libthread condVarwait rather than a nanosleep to provide interruptability and provides a minimum sleep() interval of only 20ms. lew.yobs@Eng 2000-10-18
18-10-2000