#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    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.

    Code:
    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()

    Edit: Some user/board setting is keeping me from clicking on the above link. Here's the url, just in case.
    http://pastebin.com/p1d0aV6b
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    Sorry, it's a perplexing problem so I thought I would ask in different forums and these two seemed like the ones with a decent response rate. Are these two websites linked in some way?
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    The volunteers that work these forums consider it a courtesy if posters will post links to all the sites where a question is asked to keep them from wasting time answering a question that has already been answered.

    Your post doesn't say which date/time is the unexpected one.
    Why do you expect them to be the same? Is there some doc that says that?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by NormR
    The volunteers that work these forums consider it a courtesy if posters will post links to all the sites where a question is asked to keep them from wasting time answering a question that has already been answered.

    Your post doesn't say which date/time is the unexpected one.
    Why do you expect them to be the same? Is there some doc that says that?
    That's a fair reason. Sorry about the duplication. Looks like we're going to have the exact issue you were trying to avoid, as I have posted a reply (awaiting moderation) at the other site.

IMN logo majestic logo threadwatch logo seochat tools logo