Can somebody tell me if that is normal?
If I execute the following code
import javax.swing.*;
public class TimerTest {
public static void main (String args[]) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new TimerTest();
}
});
}
public TimerTest(){
long startTime = System.currentTimeMillis();
System.out.println(startTime);
try{
Thread.sleep(20);
}
catch(Exception e){}
long endTime = System.currentTimeMillis();
System.out.println(endTime);
System.out.println("difference= "+(endTime-startTime));
}
}
I get something like:
1190718128803
1190718128827
difference= 24
So the Thread is sleeping for 24ms (always more or less between 23 and 27). I have a dual core processor and I’ve heard that nanoTimer gives difficulties with dual-core.