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 :
- Tue Jul 03 10:32:34 EEST 2012
- Tue Jul 03 10:32:34 EEST 2012
- Tue Jul 03 10:32:35 EEST 2012
- Tue Jul 03 10:32:35 EEST 2012
- Tue Jul 03 10:32:36 EEST 2012
- Tue Jul 03 10:32:36 EEST 2012 ...
However on another machine, timestamp on the console shows ScheduledThreadPoolExecutor is getting late. By getting late I mean a couple of seconds :)
- Tue Jul 03 10:32:34 EEST 2012
- Tue Jul 03 10:32:37 EEST 2012
- Tue Jul 03 10:32:40 EEST 2012
- Tue Jul 03 10:32:44 EEST 2012
- Tue Jul 03 10:32:50 EEST 2012
- Tue Jul 03 10:32:55 EEST 2012 ...
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.