Dear all,
My app needs to run 2 tasks every 10 minutes and 17 minutes respectively. FYI, my project is a class to be used by other app and do something in the background. I tried by creating 2 timers and 2 TimerTasks with the intervals set to every 5 seconds and 9 seconds.
However, after both tasks are running for 2-3 times, the 2nd task doesn't run anymore.
Below are the simplified code excerpts.
Can someone help to advise me the correct way to do this, preferrably with some sample codes? Thank you sooo much. Smiley
public class TestTimer {
private Timer timer1, timer2;
private Task1 task1;
private Task2 task2;
public TestTimer() {
timer1 = new Timer();
task1 = new Task1();
//Every 5 secs
timer1.schedule(task1, 5000, 5000);
timer2 = new Timer();
task2 = new Task2();
//Every 9 secs
timer2.schedule(task2, 9000, 9000);
}
private class task1 extends TimerTask {
public final void run() {
DoSomething1
}
}
private class task2 extends TimerTask {
public final void run() {
DoSomething2
}
}
}

Reply With Quote

