1

I have one scenario about cron job, Please see below:

import play.jobs.Job;
import play.jobs.On;

@On("1 * * * * ?")
public class TestCron2 extends Job {

    @Override
    public void doJob() {
        try {
            System.out.println("TestCron2 is calling");
            while(true){

            }

        } catch (Exception e) {
              e.printStackTrace();            
            }

        }
}

So this job is meant for running every 1 minute but at very first time it will print the message TestCron2 is calling , then it enters the infinite while loop. So it's not able to come out. So next minute onwards it is not calling because the first attempt itself is not completed yet and it won't complete also.

So can someone please clarify me the following things:

  1. Here I am putting infinite while loop to point out infinite loop situation, but in real scenario my cron job is not completed their assigned job due to some unknown reason . So it is not calling next interval of time, but it is not happening always.It happened in a month only one or two times.

  2. The solution was I need to restart the server and it again started working fine.

But Is there any way to restart the cron job without restarting the server? I hope I was able to explain this problem properly ,if not please let me know. Any help is deeply appreciated.

Vivek Pradhan
  • 4,777
  • 3
  • 26
  • 46
user3069091
  • 71
  • 1
  • 2
  • 10
  • You can use Quartz's InterruptableJob class which will allow you to interrupt a running Job --- http://stackoverflow.com/questions/7159080/how-to-interrupt-or-stop-currently-running-quartz-job – Kenneth Clark Feb 18 '15 at 07:00

0 Answers0