Quartz.NET 提供了 IStatefulJob(有状态作业)、IInterruptableJob(无状作业)这2个接口;官方文档中实现方式:
public interface IStatefulJob : IJob { } public interface IInterruptableJob : IJob { //中断方法 void Interrupt(); }
注:一个Job实例可以被定义为"有状态的"或者"无状态的"。在执行无状态的任务过程中任何对JobDataMap所作的更改都将丢失。有状态的任务恰好相反,它在任务的每次执行之后重新存储JobDataMap。有状态任务的一个缺点就是它不能并发执行。也就是说,如果任务有状态,那么当触发器试图触发它,触发器就会被阻塞直到前面的执行完成。想使任务有状态,它就要实现 IStatefulJob 接口而不是实现IJob接口。
Job类加上[DisallowConcurrentExecution]标记,可以阻止并发执行
The value stored in database is the DateTime.Ticks value. From MSDN:
A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.
The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.
public override DateTimeOffset? GetNextFireTimeUtc() { return nextFireTimeUtc; } public virtual object GetDbDateTimeValue(DateTimeOffset? dateTimeValue) { if (dateTimeValue != null) { return dateTimeValue.Value.UtcTicks; } return null; }
转换方法
SELECT DATEADD(HOUR, 8, DATEADD(SECOND, (NEXT_FIRE_TIME - 634241664000000000)/10000000, CONVERT(DATETIME, '2010-11-01'))) ,* FROM QRTZ_TRIGGERS