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 3610094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:42:33+00:00 2026-05-18T21:42:33+00:00

I am having a weird problem with timers… My Timer works correctly when testing

  • 0

I am having a weird problem with timers… My Timer works correctly when testing in NetBeans, but as soon as I compile and run directly from the terminal (Ubuntu 10.4), the task that is supposed to occur every minute executes once and never executes again…

Here is my code:

public static void main(String[] args) throws SQLException
{
    // schedule db update task to occur every 15 mins
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask ()
        {
            @Override public void run()
            {
                doUpdate();
            }
        } , 0, updateInterval * 1000 * 60 );
        System.out.print("Starting auto update @ ");

    // schedule cpu usage check to occur every 1 min
    Timer cpu = new Timer();
    cpu.scheduleAtFixedRate(new TimerTask ()
        {
            @Override public void run()
            {
                getCPU();
            }
        } , 0, cpuUpdateInterval * 1000 * 60 );
}

Is there something that I am doing wrong?

  • 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-18T21:42:34+00:00Added an answer on May 18, 2026 at 9:42 pm

    With this code,

    import java.util.Timer;
    import java.util.TimerTask;
    
    /** @see http://stackoverflow.com/questions/4503829 */
    public class TimerTest {
    
        private static final int MAX = 8;
    
        public static void main(String[] args) {
            final Timer cpu = new Timer();
            cpu.scheduleAtFixedRate(new TimerTask() {
    
                private int count;
    
                @Override
                public void run() {
                    count++;
                    System.out.println("Count: " + count);
                    if (count == MAX) {
                        cpu.cancel();
                    }
                }
            }, 100, 1000);
        }
    }
    

    I got the expected results:

    $ make run
    java -version
    java version "1.6.0_20"
    OpenJDK Runtime Environment (IcedTea6 1.9.2) (6b20-1.9.2-0ubuntu1~10.04.1)
    OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)
    java TimerTest
    Count: 1
    Count: 2
    Count: 3
    Count: 4
    Count: 5
    Count: 6
    Count: 7
    Count: 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an extremely weird problem with a PHP script of mine. I'm uploading
This is a really weird problem that I have been having. When I download
This is a weird problem I have started having recently. My team is developing
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having a weird problem using [UIImage imageNamed:] method to set table view cells'
I'm having a weird problem with hook_view. The problem is, hook_view isn't invoked unless
I'm having a weird problem with my symfony backend. I can log in once,
I am having a very weird problem with building a SQL Server 2008 Database
I am having a weird problem with a small restlet service that I am
This is kind of a weird question but... If I run this query in

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.