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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:37:58+00:00 2026-05-15T14:37:58+00:00

I have a daemon thread which wakes up at a specified interval to do

  • 0

I have a daemon thread which wakes up at a specified interval to do some task. Now I need to add two more tasks to the thread & these tasks have their own intervals. Something like

  • After every x seconds do Task1
  • After every y seconds do Task2
  • After every z seconds do Task3

So I basically need to come up with a sleep logic to ensure that all the tasks are done at the right time. What would be the most optimal way of doing this?
My thought on this was that, the times at which each task is performed is an Arithmetic Progression, so I would need to combine the AP’s corresponding to each task & use that series to figure out the time interval I need to sleep as well as the next task to perform. Does this approach make sense?

  • 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-15T14:37:59+00:00Added an answer on May 15, 2026 at 2:37 pm

    You can probably do something like this:

    now = time_in_seconds()
    time_since_task1 = x - (now % x)
    time_since_task2 = y - (now % y)
    time_since_task3 = z - (now % z)
    
    shortest_interval = min(min(time_since_task1, time_since_task2), time_since_task3)
    sleep(shortest_interval)
    

    Then you can check if the “new now” is equal to 0 mod x,y,z and do the requisite tasks.

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

Sidebar

Related Questions

I have a daemon thread which is started when a page is opened. The
Hypothetical scenario: I have a daemon thread responsible for some I/O, the main thread
I have written a simple Java dispatcher with a daemon thread to handle the
I have a small daemon that I'm writing in C and I need a
I have written a server daemon (Linux, Ubuntu) which communicates with PHP as frontend
I have a thread running under tomcat which creates a HttpUrlConnection and reads it
I have a launchd daemon that every so often uploads some data via a
Is it so memory consuming to have a daemon written on php (which listens/process
I'm trying to create a daemon thread under Windows, but I have no clue
I have read tutorial concerning background thread(or worker thread) and now I get confused

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.