Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement timeout with Quartz?

i'm trying to find the best way to implement a timeout with quartz but i want to know if this framework already contains a class or interface to do it. The timeout that need to implement it's because i want to know how long have been work the job, and take the desicion of turn off the job.

like image 584
Jorge Avatar asked Aug 24 '10 14:08

Jorge


People also ask

How do you implement Quartz scheduler?

These steps are as follows: In the first step, we have to initialize the scheduler instance from Quartz by using StdSchedulerFactory() method. After that, we start the scheduler instance with the Quartz API start() method. Start the scheduler instance with Quartz API start()

How does Quartz Scheduler work internally?

Quartz can participate in JTA transactions, via the use of JobStoreCMT (a subclass of JDBCJobStore). Quartz can manage JTA transactions (begin and commit them) around the execution of a Job, so that the work performed by the Job automatically happens within a JTA transaction.

What is quartz scheduler in spring?

Quartz is an open source Java library for scheduling Jobs. It has a very rich set of features including but not limited to persistent Jobs, transactions, and clustering. You can schedule Jobs to be executed at a certain time of day, or periodically at a certain interval, and much more.


1 Answers

Because the java platform does not provide any way to stop a thread, Quartz does not provide any way to stop a job executing on a thread.

Jobs need to take care of themselves, as Quartz can have no idea what code is in their execute() method.

I'd suggest using System.currentTimeMillis() at the beginning of your job execute() method to record the current time, and then every time through your job's main loop use it again to get the current time. Look at the difference to see if your maximum time has past,and if so break out of your main loop and exit from the execute() method.

like image 65
jhouse Avatar answered Oct 11 '22 06:10

jhouse