How to implement timeout with Quartz?
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.
Jorge
I'm a software developer with knowledge in C# javascript, Jquery .Net asp.net-mvc, web-api node.js Always interested in agile methodologies. My StackOverflow CV twitter
Updated on July 20, 2022Comments
-
Jorge almost 2 years
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.
-
jhouse almost 13 yearsAlso see the InterruptableJob interface. And the JobListener interface, which give you tools for adding some simple features to the framework that meet your needs.
-
Stefano over 3 yearsBut if the job is one shot and without loop, How can I check that you said ?