每分钟安排一次触发,如果作业仍在运行,则待机并等待下一个触发
我需要安排一个触发器每分钟触发一次,如果作业仍在运行,则下一分钟触发器不应触发,应再等待一分钟进行检查,如果作业已完成,则触发器应触发 谢谢
I need to schedule a trigger to fire every minute, next minute if the job is still running the trigger should not fire and should wait another minute to check, if job has finished the trigger should fire
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Quartz 2 中,您需要在作业类上使用
DisallowConcurrentExecution
属性。 然后确保您使用类似于 TriggerBuilder.Create().WithIdentity( "SomeTriggerKey" ) 的方式设置密钥,因为DisallowConcurrentExecution
使用它来确定您的作业是否已启动跑步。In Quartz 2, you'll want to use the
DisallowConcurrentExecution
attribute on your job class. Then make sure that you set up a key using something similar toTriggerBuilder.Create().WithIdentity( "SomeTriggerKey" )
asDisallowConcurrentExecution
uses it to determine if your job is already running.我没有找到任何关于monitor.enter或类似的东西,无论如何谢谢
另一个答案是作业应该实现“StatefulJob”接口。 作为 StatefulJob,只要一个实例已经在运行,另一个实例就不会运行
再次感谢
I didnt find any thing about monitor.enter or something like that, thanks any way
the other answer is that the job should implement the 'StatefulJob' interface. As a StatefulJob, another instance will not run as long as one is already running
thanks again
IStatefulJob 是这里的关键。 当您参与线程时,创建自己的锁定机制可能会导致调度程序出现问题。
IStatefulJob is the key here. Creating own locking mechanisms may cause problems with the scheduler as you are then taking part in the threading.
如果您使用 Quartz.NET,您可以在 Execute 方法中执行类似的操作:
我突然想到了这一点,也许有些名称是错误的,但这就是想法:在执行时锁定某个对象,如果执行时锁处于打开状态,则先前的作业仍在运行,您只需
return;
编辑:Monitor 类位于 System.Threading 命名空间中
If you're using Quartz.NET, you can do something like this in your Execute method:
I pull this off the top of my head, maybe some names are wrong, but that's the idea: lock on some object while you're executing, and if upon execution the lock is on, then a previous job is still running and you simply
return;
EDIT: the Monitor class is in the System.Threading namespace
如果您使用 Spring Quartz 集成,则可以将 MethodInvokingJobDetailFactoryBean 中的“concurrent”属性指定为“false”
If you are using spring quartz integration, you can specify the 'concurrent' property to 'false' from MethodInvokingJobDetailFactoryBean