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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:08:05+00:00 2026-06-08T16:08:05+00:00

I have been assigned on designing a java program on a linux machine that:

  • 0

I have been assigned on designing a java program on a linux machine that:

  1. Connects to a database
  2. reads a record
  3. retrieve certain information and send to Nagios according to a field known as ‘threat_level’
  4. read next record and repeat step number 3 until all records have been read

Now, I needed to get this to run every few minutes; so what my partner did was create a script that uses a loop to run the program, sleeps a few minutes, and repeat.

Recently, my boss told us that its good but would like the whole procedure to be completely self contained in java; meaning that it loops and sleeps within java. On top of that, he would like to have the sleep duration be determined by command line each time that the program is run.

I did some research and it seems that using Thread.sleep() is inefficient in certain circumstances and I cannot tell if this is one of them or not. Also, I am still unclear on how to have the sleep time be determined via command line upon running the program. I can provide the code if necessary.

  • 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-06-08T16:08:07+00:00Added an answer on June 8, 2026 at 4:08 pm

    Thread.sleep() is just fine, especially when you want to sleep for “few minutes“:

    public class Main {
    
        public static void main(String[] args) throws InterruptedException {
            final int sleepSeconds = Integer.parseInt(args[0]);
            while(true) {
                //do your job...
                Thread.sleep(sleepSeconds * 1000);
            }
        }
    
    }
    

    Thread.sleep() might be inefficient or not precise enough in millisecond time ranges, but not in your case. But if you want the process to run in the same frequency (as opposed to with fixed delay), consider:

    final long start = System.currentTimeMillis();
    //do your job...
    final long runningTime = System.currentTimeMillis() - start;
    Thread.sleep(sleepSeconds * 1000 - runningTime);
    

    This is important of “do your job” part might take significant amount of time and you want the process with exact frequency.

    Also for readability consider TimeUnit class (uses Thread.sleep() underneath):

    TimeUnit.SECONDS.sleep(sleepSeconds);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been assigned wit the task to write a program that takes a
I have been assigned to implement an interface to an API that uses XML
I'd like to create a procedure that selects all records that have been assigned
I have recently been assigned a CSS & design project that's in a CakePHP
I have been assigned the task of converting an SQL Server Database to an
I have been assigned to work on a Java/Flash/BlazeDS project. When I pull down
I have been assigned the task of unit testing a class that I never
I have been assigned to make my console program output the following: Grid (1,
I have been assigned a project to develop a set of classes that act
I have been assigned a project with a lot of poorly written code that

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.