• Quartz.net 实现单线程执行Job


    使用Quartz.net的时候经常会遇到一种情况,就是job执行速度过慢,而Quartz.net默认也是并发执行的,这就导致一种情况,之前的job还没做完,第二个就开始了,在某些业务场景下这种情况容易造成数据错乱,那么这个时候就需要把执行改成单线程执行,解决起来很简单,就是在job类加注解[DisallowConcurrentExecutionAttribute]

    具体实现方式如下,以abp vnext 实现的quartz.net为例子:

        [DisallowConcurrentExecutionAttribute]
        public class QueryWork : QuartzBackgroundWorkerBase
        {
            private IAppService _appService;
            public QueryWork(IAppService appService)
            {
                _appService = appService;
                JobDetail = JobBuilder.Create<QueryWork>().WithIdentity(nameof(QueryWork)).Build();
                Trigger = TriggerBuilder.Create().WithIdentity(nameof(QueryWork))
                    .WithDailyTimeIntervalSchedule(s => s.WithIntervalInSeconds(5)).Build();
            }
            public async override Task Execute(IJobExecutionContext context)
            {
                await _appService.QueryAsync();
            }
        }
  • 相关阅读:
    Eclipse添加注释简介
    git config配置文件
    ndk开发教程以及问题解决方案
    PATH路径出错导致任何命令都找不到解决方法
    git详细教程
    ssh相关操作
    ORM SQLAlchemy 表于表的关系
    SQLAlchemy 使用
    ORM SQLAlchemy 简介
    LUA基础
  • 原文地址:https://www.cnblogs.com/wcoolly/p/14747133.html
Copyright © 2020-2023  润新知