I have this simple code snippet :
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(10);
Runnable r = new Runnable() {
@Override
public void run() {
System.err.println(Calendar.getInstance().getTime());
}
};
exec.scheduleAtFixedRate(r,0, 500, TimeUnit.MILLISECONDS);
}
On one machine, this code runs as expected. Console output :
However on another machine, timestamp on the console shows ScheduledThreadPoolExecutor is getting late. By getting late I mean a couple of seconds :)
Details of first machine on which code runs successfully :
i3 Windows 7 64 bit JRE 1.6.0.30
Details of second machine on which scheduling running late :
Dual Core Windows XP 32 bit JRE 1.6.0.18
I wonder why there is such a difference. Any suggestions ?
Thanks in advance.
actually the schedule timer is not accurate, it calculate time by cpu ticks. so if your machine load is too heavy, there may be some delay. check your second machine's load!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With