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

  • Home
  • SEARCH
  • 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 4253656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:58:30+00:00 2026-05-21T04:58:30+00:00

I am working on a Java program and using Timer objects to run tasks

  • 0

I am working on a Java program and using Timer objects to run tasks every few minutes or hours. This works fine in normal operations, but I am running into a problem with “Sleep mode” on Mac (maybe on other OSes, but I haven’t tried yet).

Consider this code sample:

//Setup the timer to fire the ping worker (every 3 minutes)
_PingTimer.scheduleAtFixedRate(new TimerTask(){
        public void run(){
            Program.PingThread = new PingWorker(Settings.Username, Settings.UserHash, true, true);
            Program.PingThread.CheckOpenPort = true;
            Program.SwingExecutor.execute(Program.PingThread);
        }
    }, 0, 180000);

In normal operation this would fire every 3 minutes with enough accuracy (I’m not concerned about the exact second or anything). The problem with this is after sleeping the computer for a few hours or so it seems to just BLAST the system with backlogged timer requests.

It seems to be running all of the missed timer hits during sleep at once trying to make up for lost time.

Is there a way i can prevent this? I tried using synchronized and some other thread techniques, but this only ensures that they aren’t all running at the same time. They still continue to run one after another until the backlog is passed.

Thanks for any help you can provide!

  • 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-21T04:58:31+00:00Added an answer on May 21, 2026 at 4:58 am

    Have you looked at the API? It clearly states the following:

    In fixed-rate execution, each
    execution is scheduled relative to the
    scheduled execution time of the
    initial execution. 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.” In the long run, the frequency of
    execution will be exactly the
    reciprocal of the specified period
    (assuming the system clock underlying
    Object.wait(long) is accurate).

    This is one reason why you should consider using a ScheduledExecutorService. This link may also prove useful.

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

Sidebar

Related Questions

I'm working on a java program, and I have several vectors defined and filled
I'm working with a Java program that has multiple components (with Eclipse & Ant
I'm working on a Java 2D rendering program (running on 1.6.0_11), which uses external
This is a nasty one for me... I'm a PHP guy working in Java
I'm working in Java with XML and I'm wondering; what's the difference between an
I am working in Java on a fairly large project. My question is about
I recently started working in Java and was introduced to the wild and crazy
I'm used to working with PHP but lately I've been working with Java and
While working in a Java app, I recently needed to assemble a comma-delimited list
I'm working on a Java library and would like to remove some functions 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.