Quartz终止正在运行的Job
Quartz停止正在运行的JobJob的重复次数如果只有1次,那么就没有办法对其过程进行操作,如:不能暂停 停止等,
Quartz停止正在运行的Job
Job的重复次数如果只有1次,那么就没有办法对其过程进行操作,如:不能暂停 停止等,或者说是没有意义。
job每重复一次是quartz的最小单元。 如果重复次数大于1,到点击停止时为止,后面的次数就不执行了。这样做对于那些只需要执行一次的Job就不太公平了。
只能采用这样方式来停止仅重复一次的Job了:
让你的job实现InterruptableJob类,在实现类里构造interrupt()方法,最简单的就是给此方法加一个标志,
- public?void?execute(JobExecutionContext?context) ??
- ????????throws?JobExecutionException?{ ??
- ??
- ????List?emailList?=?null; ??
- ????for?(Iterator?iter?=?emailList.iterator();?iter.hasNext();)?{ ??
- ????????if?(!interrupt)?{ ??
- ????????????String?email?=?(String)?iter.next(); ??
- ?????????????????????????????????????????????????????????????????????????????????????log.debug(email?+"?is?Running"); ?
- ????????}else{ ?
- ????????????String?email?=?(String)?iter.next(); ?
- ????????????log.debug(email+"?:?is?Stopped!"); ??
- ????????} ??
- ????} ??
- } ??
- ??
- /* ?
- ?*?(non-Javadoc) ?
- ?*? ?
- ?*?@see?org.quartz.InterruptableJob#interrupt() ?
- ?*/??
- public?void?interrupt()?throws?UnableToInterruptJobException?{ ??
- ????interrupt?=?true; ??
- ??
- }??
?
这样在ProxyImpl类中调用
?????scheduler.interrupt(....);
?????scheduler.deleteJob(....);
就可以了,委婉的实现了一下这样的功能。
不知道还有别的方法没,期待中.......
1 楼 hmh1985 2007-04-18 不错,楼主的方法,我喜欢.学你呢!!!!