How to make Quartz.NET process synchronously?

这一生的挚爱 提交于 2019-12-04 03:33:04

I've used Quartz.net a bit, but never investigated enforcing serial processing between jobs. From my experience, Quartz is more intended for "parallel" scheduled processing, where jobs can overlap if they run long, so I'm not sure if it supports what you need.

A simple solution to your problem might be to use a synchronization variable that can be accessed by any of the job threads (e.g. a lock, mutex, semaphore, or global boolean, etc.). When a new job starts up, it should check the lock, and if it's free, grab it, and hold it until it's finished. If another job wakes up, and sees that a previous job is still running, the new job can just exit, and wait for the scheduler to try again on the next interval. You could also have the new job wait for the previous to finish, but if you do that, you run the risk of jobs piling up waiting to execute, and the system never "catching up."

Quartz.NET 2.x

Implement IJob and also decorate your job class with [DisallowConcurrentExecution] attribute. Read the API documentation for DisallowConcurrentExecutionAttribute for more information.

Quartz.NET 1.x

Make the job class implement IStatefulJob rather than IJob. Read the API documentation for IStatefulJob for more information.

http://www.quartz-scheduler.net/documentation/faq.html#howtopreventconcurrentfire

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