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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:27:31+00:00 2026-05-11T07:27:31+00:00

My program has a component – dubbed the Scheduler – that lets other components

  • 0

My program has a component – dubbed the Scheduler – that lets other components register points in time at which they want to be called back. This should work much like the Unix cron service, i. e. you tell the Scheduler ‘notify me at ten minutes past every full hour’.

I realize there are no real callbacks in Java.

Here’s my approach, is there a library which already does this stuff? Feel free to suggest improvements, too.

Register call to Scheduler passes:

  • a time specification containing hour, minute, second, year month, dom, dow, where each item may be unspecified, meaning ‘execute it every hour / minute etc.’ (just like crontabs)
  • an object containing data that will tell the calling object what to do when it is notified by the Scheduler. The Scheduler does not process this data, just stores it and passes it back upon notification.
  • a reference to the calling object

Upon startup, or after a new registration request, the Scheduler starts with a Calendar object of the current system time and checks if there are any entries in the database that match this point in time. If there are, they are executed and the process starts over. If there aren’t, the time in the Calendar object is incremented by one second and the entreis are rechecked. This repeats until there is one entry or more that match(es). (Discrete Event Simulation)

The Scheduler will then remember that timestamp, sleep and wake every second to check if it is already there. If it happens to wake up and the time has already passed, it starts over, likewise if the time has come and the jobs have been executed.


Edit: Thanks for pointing me to Quartz. I’m looking for something much smaller, however.

  • 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. 2026-05-11T07:27:32+00:00Added an answer on May 11, 2026 at 7:27 am

    If your needs are simple, consider using java.util.Timer:

    public class TimerDemo {    public static void main(String[] args) {     // non-daemon threads prevent termination of VM     final boolean isDaemon = false;     Timer timer = new Timer(isDaemon);      final long threeSeconds = 3 * 1000;     final long delay = 0;     timer.schedule(new HelloTask(), delay, threeSeconds);      Calendar calendar = Calendar.getInstance();     calendar.add(Calendar.MINUTE, 1);     Date oneMinuteFromNow = calendar.getTime();      timer.schedule(new KillTask(timer), oneMinuteFromNow);   }    static class HelloTask extends TimerTask {     @Override     public void run() {       System.out.println('Hello');     }   }    static class KillTask extends TimerTask {      private final Timer timer;      public KillTask(Timer timer) {       this.timer = timer;     }      @Override     public void run() {       System.out.println('Cancelling timer');       timer.cancel();     }   }  } 

    As has been noted, the ExecutorService of java.util.concurrent offers a richer API if you need it.

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer After some consideration, I decided to remove the usage of… May 11, 2026 at 12:55 pm
  • added an answer Get any element that doesn't have any other element: $('*:not(:has(*))'); May 11, 2026 at 12:55 pm
  • added an answer Instead of forwarding the signal to the debuggee from Python,… May 11, 2026 at 12:55 pm

Related Questions

All objects in my program inherit from a Container class. The Container class has
I have a setup project for my C# program, and this setup project has
This is my problem. I have a program that has to run in a
I'm trying to make a program in Visual C# that has my one created
My program has to read files that use various encodings. They may be ANSI,
My program has a component - dubbed the Scheduler - that lets other components
I've been trying to learn about Neural Networks for a while now, and I
I'm working on a program that processes many requests, none of them reaching more
I was worrying about race conditions in an application I'm designing, when I was

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.