maybe you could help to understand some things about TimerClass:
Assume i got a timer
Timer timer = new Timer();
And a data-fetching task
timer.shedule(new DataFetcher, 0, time);
Assume a short interval to execute the task plus an theoretical infinite running program, may it appear that, when the period is short enough or the execution of the task takes too long, i'll end up with lots of DataFetcher instances? If i change the sheduling
DataFetcher df = new DataFetcher();
timer.shedule(df, 0, time);
would this ensure that i'd always work with the same task instance? I tried to simulate that, to estimate the behaviour, but i'm kinda stuck.
Greetings
Please notice that im working on a mobile device using j2me. I know about timer alternatives in std java but i guess its not suitable for the microedition.
Both your versions are the same: you will have only one instance of DataFetcher
, which is the proper way to do it.
Also, from the documentation:
In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well.
Therefore the tasks will not accumulate, they are executed one after an other.