Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    I've run into the oddest problem which really isn't making any sense.

    Timer timer = new Timer();
     
    //7 days
    long patchNotesSleep = 7 * 24 * 60 * 60 * 1000;
     
    TimerTask task = new TimerTask() {public void run() {}};
     
    //Schedule at 14:55 on the next Thursday
    Date nextDate = calcPatchNotesStartDate();
     
    timer.scheduleAtFixedRate(task, nextDate, patchNotesSleep);
     
    System.out.println("Should start at " + nextDate);
    System.out.println("Patch Notes scheduled to check at " + new Date(task.scheduledExecutionTime()));

    What I'm expecting is for the two print statements to return the same dates. What I'm actually getting is this.

    Should start at Thu Mar 14 14:55:00 EDT 2013
    Patch Notes scheduled to check at Thu Mar 07 13:55:00 EST 2013
    I've tried throwing breakpoints and comparing the actual date objects, just in case something weird was going on with the print. They are different dates.

    Source code for calcPatchNotesStartDate()


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Can you post the definition for: calcPatchNotesStartDate()
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Also posted at: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day - Dev Shed


    I'm expecting is for the two print statements to return the same dates
    You don't say which date you expect to be printed.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Quote Originally Posted by Norm View Post
    Also posted at: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day - Dev Shed



    You don't say which date you expect to be printed.
    I'm expecting it to start on the date returned by calcPatchNotesStartDate(), since that is the date I am passing in to the scheduleAtFixedRate method.

    The source code for calcPatchNotesStartDate() is in the pastebin link at the bottom of the opening post called "Source code for calcPatchNotesStartDate()". I didn't want to clutter the post with a longer bit of code.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Quote Originally Posted by Norm View Post
    Also posted at: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day - Dev Shed



    You don't say which date you expect to be printed.
    I'm expecting it to start on the date returned by calcPatchNotesStartDate(), since that is the date I am passing in to the scheduleAtFixedRate method.

    The source code for calcPatchNotesStartDate() is in the pastebin link at the bottom of the opening post called "Source code for calcPatchNotesStartDate()". I didn't want to clutter the post with a longer bit of code.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Read the API doc for the scheduledExecutionTime() method and see if it does what you expect.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Timer.scheduleAtFixedRate() is scheduling itself to run on the wrong day

    Quote Originally Posted by Norm View Post
    Read the API doc for the scheduledExecutionTime() method and see if it does what you expect.
    I see. Apparently I was misreading what that method did. Thanks.

Similar Threads

  1. Can't Get Timer to Work, What Am I doing Wrong?!?!
    By Liikeaturtle in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 29th, 2012, 09:43 PM
  2. My code will not run like I want it to. What is wrong???
    By koolestkid20 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 24th, 2012, 08:35 PM
  3. We use to run code to get a few thousand Google Page Ranks each day.
    By petersonlee.cc@gmail.com in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2012, 11:18 AM
  4. Replies: 2
    Last Post: January 6th, 2012, 10:50 PM
  5. My code has error when its run....I dont understand what's wrong of it.
    By jacky@~ in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 11th, 2011, 07:48 AM