java 立即使用 Quartz 完成一次性任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4065619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Immediate one time task with Quartz
提问by rook
I am using a Quartzto build a clustered ThreadPool and I have number of tasks that run at various times. What is the best way to run 1 task immanently and only once on the clustered ThreadPool. I know I can set the task to a high priority. But what is the best way to register a "one shot" task?
我正在使用Quartz来构建集群线程池,并且我有许多在不同时间运行的任务。在集群线程池上永久运行 1 个任务且仅运行一次的最佳方法是什么。我知道我可以将任务设置为高优先级。但是注册“一次性”任务的最佳方法是什么?
采纳答案by Brad Mace
I feel like I must be missing something, or maybe you just overlooked this bit in the docs:
我觉得我一定遗漏了一些东西,或者您可能只是忽略了文档中的这一点:
public SimpleTrigger(String name, String group, Date startTime, Date endTime, int repeatCount, long repeatInterval)
public SimpleTrigger(String name, String group, Date startTime, Date endTime, int repeatCount, long repeatInterval)
SimpleTrigger trigger = new SimpleTrigger("myTrigger",
null,
new Date(),
null,
0,
0L);
回答by Patrick Twohig
You can also use the TriggerBuilderclass to make life a little bit easier. It's similar to what was posted before, just a little cleaner.
您还可以使用TriggerBuilder类让生活更轻松一些。和之前贴的差不多,只是简洁了一点。
Trigger trigger = TriggerBuilder.newTrigger()
.startNow()
.build();
回答by Pavel Vlasov
The easiest way to trigger an one-shot for a pre-registered job:
触发预注册作业一次性的最简单方法:
Scheduler sched = ...
scheduler.triggerJob(jobKey);