I have some tasks that are executed with the help of Java Quartz Jobs, but I need to stop some tasks by some condition in my code. I read that this can be done via InterruptableJob. But i didn't understand in what way i should do it?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I don't know why nobody mentioned this, or maybe this was not available at the time the question was asked.
There is a method called shutdown for a Scheduler instance.
The above is used to start a job like
Use a flag or something to know when to stop the job from running. Then use
How I implemented my requirement:
Where jobDetail and simpleTrigger are self explanatory.
Hope it helps. :)
The best solution in my opinion is the one described in this thread: http://forums.terracotta.org/forums/posts/list/7700.page
I've just introduced a "sleep" after set stop flag to true to allow the job to finish cleanly.
In Quartz 2.1 with Spring you can:
You need to write a your job as an implementation of InterruptableJob. To interrupt this job, you need handle to Scheduler , and call
interrupt(jobKey<<job name & job group>>)
Please have a look @ javadoc for above classes, also quartz distribution contains an example for this (example7).