0

I need to write a Java class, which fetches different times from a database and then calls a function at those times. The times can change in the database and a value corresponding to the time in the Db is sent as arguments to the function. I need to make sure this happens everyday at the time mentioned in the Db.

 Scheduler s = new Scheduler();
    s.schedule("0 5 * * *", new Runnable() {
        public void run() {
            //call your function
            TestClass tc = new TestClass(value);
        }
    });
    // Starts the scheduler.
    s.start();
    try {
        Thread.sleep(1000L * 60L * 10L);
    } catch (InterruptedException e) {
        ;
    }
    // Stops the scheduler.
    s.stop();

This code calls the class at 5:00:00 everyday, but I'm not sure what to pass in Thread.sleep() I need to write for multiple different times too and make sure it runs for a long time, i.e. over a year.

Yajat Singh
  • 43
  • 1
  • 1
  • 8

1 Answers1

0

If you want this to run for a year, then you shouldn't sleep(). You need to have your Scheduler stopped only of your application is shutting down. So as long as your application is running, supposedly for a year or more , your scheduler should be running too.

Muhammad Gelbana
  • 3,890
  • 3
  • 43
  • 81