×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    27

    Running more than 1 TimerTask with Timers

    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
    }
    }

    }

  2. #2
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Running more than 1 TimerTask with Timers

    you sure you don't want to use the scheduleAtFixedRate method instead ?

Similar Threads

  1. Running 'Hello World'
    By 76Richard76 in forum Mobile Java Tools & SDKs
    Replies: 5
    Last Post: 2009-07-07, 14:44
  2. Replies: 4
    Last Post: 2009-04-27, 19:51
  3. Replies: 1
    Last Post: 2006-06-08, 03:49
  4. 3d game app running slowly
    By venkat512 in forum Mobile Java General
    Replies: 3
    Last Post: 2006-05-18, 06:47
  5. Replies: 1
    Last Post: 2006-03-23, 07:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×