Thread.sleep(500) will suspends current thread for at least 500 milliseconds i know it may be little more than 500 but it never less than that. Now 1 millisecond=1000000 nanoseconds I want to suspend current thread for 500 milliseconds i.e.=500*1000000 nanoseconds But when i run the following code it sometimes sleep less than specified value in nanoseconds. Why is this? and how to sleep for at least 500*1000000 nanoseconds.
long t1=System.nanoTime();
try{
Thread.sleep(500);
}catch(InterruptedException e){}
long t2=System.nanoTime();
System.out.println((t2-t1)+" nanoseconds");
System.out.println((500*1000000-(t2-t1))+" nanoseconds");
sometimes Output is
499795328 nanoseconds
204672 nanoseconds