问题
...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