What happens in Quartz.NET/Quartz when

和自甴很熟 提交于 2019-12-08 04:53:16

问题


...when a job is still being executed when its next execution time occurs?

For example, if I have a job that occurs every 30 seconds, and after the 30 seconds it is still operating, would the next instance come into play or would it wait?


回答1:


The short answer is that a new job will be executed, unless you are inheriting from IStatefulJob, in which case only one job instance is allowed to run at a time.




回答2:


As TskTsk answered, you can implement IStatefulJob insted of IJob but there is a catch! If you are having job that is executing more than 30 seconds (thus you have on or more jobs waiting this one to finish), after its execution all jobs that were waiting will fire immidietly! To overcome this you need to create new class that implements SimpleTrigger. This new trigger class should have overriden GetFireTimeAfter.

public class MyTrigger : SimpleTrigger
{

    public MyTrigger(string name,
                     string group,
                     DateTime startTimeUtc,
                     DateTime? endTimeUtc,
                     int repeatCount,
                     TimeSpan repeatInterval) : base(name, startTimeUtc, endTimeUtc, repeatCount, repeatInterval)
    {
    }

    public override DateTime? GetFireTimeAfter(DateTime? afterTimeUtc)
    {
        return DateTime.UtcNow.AddSeconds(RepeatInterval.TotalSeconds);
    }

}

This way the next job will not execute immidietly after first one is finished.



来源:https://stackoverflow.com/questions/3995562/what-happens-in-quartz-net-quartz-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!