timer

Hi.

I've written a java program that runs in a Windows 2000 environment and has a timer which calculate a lot of things. I observed what I think is sort of weard behaviour. Then I wrote a very simple program to see if I get the same behaviour. I did it.

Observe the program:

mport java.util.Timer;

import java.util.TimerTask;

//

publicclass Principal{

publicstaticvoid main(String[] args){

System.out.print("orloge: ");

Timer orloge =new Timer();

orloge.scheduleAtFixedRate(

new TimerTask(){

publicvoid run(){

System.out.print(".");

}},

2000,

3000);

}

}

It produces a line like this:

orloge: ............

Each point is wirtten each 2 seconds.

If you run this program you will get the same result. No problem.

The weird behaviour begins when you alter the system clock with "date and time properties". If I advance the clock some minutes, the program simply executes the timer task as if it were in a hurry. On the other hand, if I delay the clock some amount time of time, the program will stop until the time gets to the point when it was altered.

It seems that the timer doesn't work on ticks but on "clock time" if you understant me.

I'm still using an old version of java:

D:\Vazio>java -version

java version "1.4.2_14"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_14-b05)

Java HotSpot(TM) Client VM (build 1.4.2_14-b05, mixed mode)

Any help is very welcome.

Ricardo

[2222 byte] By [JoursChampsa] at [2007-11-27 4:49:20]
# 1
> It seems that the timer doesn't work on ticks but on "clock time" if you understant me.Okay. So you did some research and found out how it works. (That's good, actually, a lot of people who post here would have no idea how to do that.) But do you have a question about it?
DrClapa at 2007-7-12 10:02:25 > top of Java-index,Java Essentials,New To Java...
# 2

Dr. Clap.

Thank you for your quick reply but ... oh yes, I do have a question!.

Is that behaviour correct?

Explaining it better: it seems to be that the described behaviour is a bug!

Even if you think that people do not change the system clock very often, there are at least two known situations when the system do it by itself: when it enters daylight save time and when it leaves dayligh save time. Both times the described behaviour has the possibility - if not the certainty - of crashing threads that depends on the timer behaviour.

Yet in another way: is there a timer that works "counting time" instead of "following the clock"?

Thansk again.

Ricardo

JoursChampsa at 2007-7-12 10:02:25 > top of Java-index,Java Essentials,New To Java...
# 3

> Even if you think that people do not change the

> system clock very often, there are at least two known

> situations when the system do it by itself: when it

> enters daylight save time and when it leaves dayligh

> save time. Both times the described behaviour has the

> possibility - if not the certainty - of crashing

> threads that depends on the timer behaviour.

Yes, I think that people do not change the system clock very often. The system does, as you say, but you seem to be assuming that Java timers will be disrupted by that. You missed doing that research.

> Yet in another way: is there a timer that works

> "counting time" instead of "following the clock"?

There's only a "problem" when people change the system clock. It's not worth worrying about in my opinion.

DrClapa at 2007-7-12 10:02:25 > top of Java-index,Java Essentials,New To Java...