Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4270304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:17:16+00:00 2026-05-21T07:17:16+00:00

I have scheduled a TimerTask to run at a fixed time with a interval

  • 0

I have scheduled a TimerTask to run at a fixed time with a interval of one day using java.util.Timer.scheduleAtFixedRate(). The TimerTask is having a logic to control the excution for a duration say 6 hours. The timer is suppose to start this task next day same given time. But sometime the task is restarted just as soon as it stops after the duration. I have not seen any pattern of this occurance, it just happens randomly. I have tested this by running this application many times but could not identify any particular pattern.

Its something like this.

class App{
  public static void main(final String[] args) {
    Timer timer = new Timer();
    ProcessManagerTask processManager = new ProcessManagerTask()
    timer.scheduleAtFixedRate(processManager, today @ 01 AM, 1440 minutes))
    //some logic to keep this running forever
  }
}

public class ProcessManagerTask extends TimerTask {
  public ProcessManagerTask(){
    //end time = today @ 7 AM
  }
  public void run() {
    while(end time is not expired){
      //do some stuff
    }
}

The ProcessManagerTask sometime restart immediately at 7 (when the task is over).

EDIT: Guys any idea why the problem appearing for Timer. I am still not able to figure out.

EDIT [08 April 2011]: Guys problem with Timer is still not resolved. I would appreciated if some one can help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:17:16+00:00Added an answer on May 21, 2026 at 7:17 am

    From the docs:

    If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to “catch up.”

    Therefore, it would appear that your task was not executed at exactly 1 AM, so was executed twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: package application; import java.util.Timer; import java.util.TimerTask; public class Application
I tried everything. This one too How to stop the task scheduled in Java.util.Timer
I have a job stored on a database, scheduled to run every day. But
I am trying to create a Timer/TimerTask that will run the same day of
I want to have an operation(Task) to be Scheduled after some time OR Based
We have implemented a process in one of the systems where it's scheduled to
Possible Duplicate: ASP.Net:Best way to run scheduled tasks I have to make a scheduled
I have a question about the behaviour of Timer class in Java. This is
So I'm running a Java server and in one class I have a static
I have a service which contains a Timer and TimerTask for receiving data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.