Quartz.NET笔记整理,实例,动态改变周期调度。misfire、Cron

手把手教你学BSP(11.3)--BSP实例:基于Raspberry Pi 4 Model B的Linux BSP开发实例 通过以上步骤,我们完成了一个基于Raspberry Pi 4 Model B的Linux BSP开发过程,包括硬件初始化、设备驱动编写、Bootloader配置、内核配置和编译,以及最终映像的生成。每个步骤都非常重要,确保每一步都正确无误才能使整个系统正常运行。 阅读详情

Quartz:Java编写的开源的任务调度作业框架 类似Timer之类定时执行的功能,但是更强大

Quartz.NET:是把Quartz转成C#  NuGet中可以直接下载对应类库

官网:https://www.quartz-scheduler.net/

主要对象:

  • Job :工作,要执行的具体内容继承IJob。此接口中只有一个方法:execute(IJobExecutionContext context) 
  • JobDetail:具体的可执行的调度程序,Job 是这个可执行程调度程序所要执行的内容
  • Trigger:调度参数的配置,什么时候去调 执行间隔。 
  • Scheduler:调度容器,一个调度容器中可以注册多个 JobDetail 和 Trigger。当 Trigger 与 JobDetail 组合,就可以被 Scheduler 容器调度了。 

大体介绍:

 static void Main(string[] args)
        {
            Task<IScheduler> task_scheduler = StdSchedulerFactory.GetDefaultScheduler();
            IScheduler scheduler = task_scheduler.Result;

            //ISchedulerFactory _SchedulerFactory = new StdSchedulerFactory();
            //IScheduler scheduler = _SchedulerFactory.GetScheduler().Result;

            /*  
             *   过程:
             *      一.通过StdSchedulerFactory计划工厂对象创建调度计划Scheduler
             *      二.创建Job对象,需要继承IJob 实现执行方法
             *      三.触发对象,2种:间隔执行和定时执行
             *          1.ITrigger:间隔执行
             *          2.ICronTrigger:定时执行
             *      四.将job对象和触发对象传入调度计划Scheduler 开始执行
             *  
             * 
             */
            //job创建
            IJobDetail job = JobBuilder.Create<SayHello>().WithIdentity("定时确认完成订单").Build();

            ////创建简单计时器
            //ISimpleTrigger _SimpleTrigger = TriggerBuilder.Create()
            //    .WithSimpleSchedule(t => t //声明定时
            //    .WithIntervalInSeconds(2) //5秒一次
            //    .RepeatForever()) //永远执行
            //    .StartNow() //立即开始
            //    .Build() //创建
            //    as ISimpleTrigger;
            ////关联job与计时器
            //scheduler.ScheduleJob(job, _SimpleTrigger);
            /*
             * WithCronSchedule参数说明:
             *  秒 分 时 某一天 月 周 年(可选参数,一般不用)
             *  秒分的合法值为0-59,小时:0-23,日期(天):0-31[要注意不同的月份中的天数不同] 月:0-11[或JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC] 星期:1-7(1=星期日)或[SUN,MON,TUE,WED,THU,FRI,SAT]    (程序员数数法。。 万事0开始)( 涉及到星期最好用英文)
             *      通配符{[, - * /]都可以使用、[L #]只能星期课额外使用、[L W]天数可额外使用}
             *          ',' 子条件
             *          '*' 代表任意值的所有 
             *          '-' 代表一个时段 
             *          '/' 代表值的增量 
             *                  比如:分钟域中放入'0/15' 表示【从0开始 每隔15分钟】 '3/20'表示【从第3分钟开始 每隔20分钟】 等同【3,23,43】
             *          '?' 只能用在天数或者星期中 表示【没有指定值,满足所有】 
             *          'L' 只能用在天数或者星期中 表示【这个时段的最后一天】 
             *                  比如:月份中 1月的31号 2月的28或者29号 反正最后一天,或者 4L:该月的最后一个周四 6L:该月的最后一个周四。  
             *                  注意!星期中表示【周六 SAT(手动加粗)】 
             *          'W' 代表离给定日期最近的那个工作日
             *                  比如:天数设置为15W 表示【离本月15号最近的一个工作日】??
             *          'LW'代表这个月最后一周的工作日 可以在日期使用 ?待测
             *          '#' 代表本月的第几个工作日
             *                  比如:星期中设置6#3 当月的第三个周五(6是周五!)
             * 
             *  过失触发:
             *    withMisfireHandlingInstructionDoNothing--->misfireInstruction = 2
             *     ——不触发立即执行
             *     ——等待下次Cron触发频率到达时刻开始按照Cron频率依次执行
             *
             *    withMisfireHandlingInstructionFireAndProceed--->misfireInstruction = 1
             *     ——以当前时间为触发频率立刻触发一次执行
             *     ——然后按照Cron频率依次执行
             *
             *     withMisfireHandlingInstructionIgnoreMisfires--->misfireInstruction = -1
             *     ——以错过的第一个频率时间立刻开始执行
             *     ——重做错过的所有频率周期后
             *     ——当下一次触发频率发生时间大于当前时间后,再按照正常的Cron频率依次执行
             * 
             * 
             * 
             * 实例:
             *      "0 0/5 * * * ?" 每5分钟
             *      "10 0/5 * * * ?" 这分钟后 10 秒起, 每五分钟
             *      "0 30 10-13 ? * WED,FRI" 每周三、周五的10点到13点的30分时 【每周三, 周五 10:30, 11:30, 12:30 和 13:30】
             *      "0 0/30 8-9 5,20 * ?" 每个月的5号、20号的8点9点之间 每半小时触发一次 因为0开始 所以10点的时候不触发【8:00, 8:30, 9:00  9:30 】
             *      "0 0-5 14 * * ?"  每天的14:00到14:05分每分钟一次
             *      "0 10,44 14 ? 3 WED" 每年三月的周三14:10和14:44
             *      "0 15 10 ? * MON-FRI" 每周三到周五的10::15
             *      "0 15 10 ? * 6#3" 每个月第三个周五的10:15
             * 
             *   生成表达式的网站:http://cron.qqe2.com/?tdsourcetag=s_pctim_aiomsg 小时模块的增量有bug注意下 但大体不影响使用
            */
            ICronTrigger _CronTrigger = TriggerBuilder.Create()
                .WithIdentity("定时确认")
                .WithCronSchedule("0/2 * * * * ?") //秒 分 时 某一天 月 周 年(可选参数)
                .Build()
                as ICronTrigger;
            scheduler.ScheduleJob(job, _CronTrigger);


            scheduler.Start();
            Console.ReadLine();
        }
    }

    public class SayHello : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            Console.WriteLine("Hello Wrold!");
        }
    }

 

 

实例:

1.创建job

 public class SayHello : IJob
    {
        public static int ii = 0;
        static string str = "服务1=Cron 5秒一次。Hello World==SayHello  ";
        public async Task Execute(IJobExecutionContext context)
        {
             
            if (ii == 1)
            {
                QuartzManage.ModifyJob(context.JobDetail, context.Trigger as ICronTrigger, "0/2 * * * * ?");
                ii = 0;
                str += ",周期已改变!!变成2秒一次 ";
            }
            Common.WriteLog(str + context.Scheduler.GetHashCode());
        }
    }

    public class SayCZ : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            Common.WriteLog("服务2=Simple 3秒一次。Hello CZ==SayCZ  " + context.Scheduler.GetHashCode());
        }
    }

2.Quartz管理类

public class QuartzManage
    {
        static Task<IScheduler> task_scheduler = StdSchedulerFactory.GetDefaultScheduler();
        static IScheduler scheduler;
        private static readonly object objlock = new object();
        static QuartzManage()
        {
            if (scheduler == null)
            {
                lock (objlock)
                {
                    if (scheduler == null)
                        scheduler = task_scheduler.Result;
                }
            }
        }

        /// <summary>
        /// 以Simple开始一个工作
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="simpleInterval"></param>
        public static void StartJobWithSimple<T>(string name, Action<SimpleScheduleBuilder> simpleInterval) where T : IJob
        {
            IJobDetail job = JobBuilder.Create<T>().WithIdentity(name + "_job", name + "_group").Build();
            ITrigger Simple = TriggerBuilder.Create().StartNow()
                               .WithSimpleSchedule(simpleInterval)
                               .Build() as ISimpleTrigger;

            scheduler.ScheduleJob(job, Simple);
            scheduler.Start();
        }

        /// <summary>
        /// 以Cron开始一个工作
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="CronExpression"></param>
        public static void StartJobWithCron<T>(string name, string CronExpression) where T : IJob
        {

            IJobDetail job = JobBuilder.Create<T>().WithIdentity(name + "_job", name + "_group").Build();

            ITrigger CronTrigger = TriggerBuilder.Create().StartNow().WithIdentity(name + "_trigger", name + "_group")
                                    .WithCronSchedule(CronExpression, w => w.WithMisfireHandlingInstructionDoNothing())
                                    .Build() as ICronTrigger;

            scheduler.ScheduleJob(job, CronTrigger);
            scheduler.Start();
        }

        /// <summary>
        /// Cron修改频率
        /// </summary>
        /// <param name="job"></param>
        /// <param name="trigger"></param>
        /// <param name="CronExpression"></param>
        public static void ModifyJob(IJobDetail job, ICronTrigger trigger, string CronExpression)
        {
            ICronTrigger _ICronTrigger = trigger;
            _ICronTrigger.CronExpressionString = CronExpression;

            scheduler.RescheduleJob(trigger.Key, _ICronTrigger);
        }

        /// <summary>
        /// Simple修改频率
        /// </summary>
        /// <param name="job"></param>
        /// <param name="trigger"></param>
        /// <param name="SimpleTime"></param>
        public static void ModifyJob(IJobDetail job, ISimpleTrigger trigger, TimeSpan SimpleTime)
        {
            ISimpleTrigger _ISimpleTrigger = trigger;
            _ISimpleTrigger.RepeatInterval = SimpleTime;

            scheduler.RescheduleJob(trigger.Key, _ISimpleTrigger);
        }

    }

3.执行调度,并改变周期

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        /// <summary>
        /// Cron
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            QuartzManage.StartJobWithCron<SayHello>("first", "0/5 * * * * ?");
        }

        /// <summary>
        /// Simple运行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            QuartzManage.StartJobWithSimple<SayCZ>("second", x => x.WithIntervalInSeconds(3).RepeatForever()); //每三秒 一直执行
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SayHello.ii = 1;
        }
    }

执行结果:

改变周期后 会有一个过时触发的问题 根据设置不同的模式 执行的效果不同 misfire的概念,第一个代码块中有详细注释说明

 

代码实例: https://download.youkuaiyun.com/download/commandbaby/10664266

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM) 迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM) 立即下载

相关推荐

LK32T102 单片机 操作GPIO实现流水灯(1)

前言: LK32T10232(32位)单片机是一款专为电机控制器和数字电源开发的高性能 MCU。采Cortex-M0 内核,最高工作频率可达 72Mhz,ADC 采样速率 达 1Msps。同时具备协处理器单元可满足各种乘法、除法、移位以及各种 复杂函数运算。 LK32T102(32位)支持单电源供电,且内嵌高精度高速及低速振荡器,以及具备 多种低功耗工作模式。同时,集成了多路增强型 PWM,多通道模拟比较 器和高速运算放大器,可满足多种电机及功率控制应用,并简化系统成本。...

qq_58676187的博客 3189

Quartz定时任务的使用(仅参考不全)

一、引入NuGet包 二、JobScheduler /// <summary> /// IScheduler:单元/实例,在这里去完成定时任务的配置 /// </summary> public class JobScheduler { private static object lockHelper = new object(); private static IScheduler scheduler = null

真的张小刀 272

从AND到XOR:5种门控电路在PrimeTime中的检查策略差异

本文深入探讨了AND、NAND、OR、NOR和XOR五种门控电路在PrimeTime静态时序分析中的检查策略差异。重点解析了XOR门控因其非单调性而无法被工具自动推断,需要工程师手动配置的特殊性,并提供了针对各类门控的配置模板与调试技巧,以确保时钟网络的完整性与芯片设计的可靠性。

rgv2345678的博客 269

quartz-misfire 错失、补偿执行

调度(scheduleJob)或恢复调度(resumeTrigger,resumeJob)后不同的misfire对应的处理规则 misfire产生的条件是:到了该触发执行时上一个执行还未完成,且线程池中没有空闲线程可以使用(或有空闲线程可以使用但job设置为@DisallowConcurrentExecution)且过期时间已经超过misfireThreshold就认为是misfire了,错失触发了 比如:13:07:24开始执行,重复执行5次,开始执行时,quartz已经计算好每次调度的时间刻,分别如下:

涂作权的博客 2836

Android 13 系统定制:实现第三方Launcher预置与原生Launcher3的共存切换

本文详细介绍了在Android 13系统中实现第三方Launcher预置与原生Launcher3共存切换的技术方案。通过修改ResolverActivity逻辑、处理首次启动设置以及优化用户切换机制,开发者可以灵活定制默认Launcher,同时保留用户自由选择权。文章还提供了常见问题排查指南和性能优化建议,帮助提升双Launcher方案的稳定性和用户体验。

weixin_30275415的博客 126

PCB之AD层次化原理图设计

PCB之AD层次化(模块化)原理图设计 软件版本:AD17.1.9(bBuild 592) 先上效果图: 可以看到,图中有RS485和W5500这两个部分是复用了原理图,当项目中需要多个功能相同的电路时,这种设计就可以大大节约PCB布局布线的时间,方法后面介绍; 1.首先确定好项目中个部分电路的功能模块 不同功能的电路分开不同原理图画,然后给出输入输出端口,这样方便复用,下面是实例项目的功能划分 2.单个模块电路的接口设计 这里以W5500以太网接口电路为例说明: 主要就分为通讯接口和电源接口:

洋洋洋的博客 3万+

Quartz定时任务不定时执行

自己的记录

weixin_43555115的博客 3510

微机原理与接口技术第六版周荷琴课后习题答案及解析(期末重点)

第二章 1.8086/8088CPU可直接寻址多少个内存(字节)单元?多少个I/O端口?它们的外部数据总线各有多少根? 8086/8088CPU使用的是20位地址总线,因此可以直接寻址2的20次方个内存单元(即1,048,576),每个单元大小为1字节,因此可以直接寻址2的20次方个字节的内存。 8086/8088CPU有64K个I/O端口,每个端口占用1字节的地址空间,因此可以直接寻址6...

Wmicheng的博客 1万+

使用quartz实现不重启服务器修改自定义配置

为了方便维护系统,开发中通常会设置一些自定义参数,写在单独的配置文件里,需要调整时可直接登录服务器修复配置文件,而不需要修改程序。但尴尬的是,web服务器并不会自动重新加载配置文件,重启服务器又会中断服务。本文是一个使用quartz解决此问题的示例。 项目结构: 其中,system.properties是自定义配置文件,内容只有一行: debug=false这个定义了一个debug参

分享知识、分享进步 3893

Seurat 单细胞转录组测序数据分析教程(三)——python(scanpy)

文章参考至,做了一个更详细的解读。本教程探讨了 scanpy 的可视化可能性,分为三个部分:嵌入的散点图(例如 UMAP、t-SNE)使用已知标记基因鉴定簇差异表达基因的可视化在本教程中,我们将使用来自 10x 的数据集,其中包含来自PBMC的 68k 个细胞。Scanpy 在其分布中包括该数据集的简化样本,该数据集仅包含 700 个细胞和 765 个高度可变的基因。该数据集已经过预处理和 UMAP 计算。在本教程中,我们还将使用以下文献标记:B细胞:CD79A、MS4A1。

coffeeii的博客 5827

12-RK平台U-Boot启动流程

先看概述,把这一章要回答的问题摆出来,带着问题听。RK 特有的 BootROM -> MiniLoader -> SPL -> U-Boot -> Kernel。这是因为 RK 平台使用闭源的 DDR 初始化固件,需要通过 MiniLoader 来加载和运行。为什么多一层?这是 RK 平台的特殊性决定的。RK 平台使用闭源的 DDR 初始化固件,这段代码 Rockchip 不开源,只能以二进制形式提供,它需要一个载体来加载和运行,这个载体就是 MiniLoader。

内核笔记 1147

【quartz】定时任务时间在数据库中修改,无需启动服务

一、修改定时任务时间方法 update qrtz_cron_triggers set CRON_EXPRESSION='0 */1 * * * ?' where TRIGGER_NAME='myTrigger1'; update qrtz_triggers set NEXT_FIRE_TIME=0,PREV_FIRE_TIME=0 where TRIGGER_NAME='myTrigger1'; 第一条sql语句是更改表qrtz_cron_triggers,原来数据库中该任务是每5分钟执行一次

yuxiangdeming的博客 4848

操作系统实验一到实验九合集(哈工大李治军)

操作系统实验一到实验九合集(哈工大李治军) 有详细代码及注释,程序已在本地测试,均能跑通

leoabcd12的博客 5万+

quartz对于定时任务Misfire的处理

使用quartz过程中,产生了很多问题,遇到就记录一下,虽然用的比较少了,但还是有一些项目在使用。 问题描述:创建一个每天执行的任务test1,创建自动运行状态,然后停止任务,一直等到当天定时时间过去,然后再启动,发现定时任务还是先执行了一次,目前这个与要实现的效果有点不相符,查找半天才发现这个Misfire 不同的misfire对应的处理规则: CronTrigger withMisfireHandlingInstructionDoNothing ——不触发立即执行 ——等待下次Cron触发频

千羽公子的专栏 1944

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

使用Quartz.net实现多线程任务定时执行,动态配置Job,结合Topshelf构建Windows服务

几个月前有这么个需求:需要执行一些Job,这些Job会各自按照不同的时间频次执行,且它们做的事情也不同,有的是监控站点,有的是监控服务器存储情况,有的是监控报表PROCEDURE的执行状况… OK,当看到这么个需求,首先我想肯定是要用多线程来处理了,并且还要考虑到性能问题,领导当时给出一个方案,建议看一下Quartz.net,于是,研究了几天,看了不少资料,总算把监控引擎做出了一个版本,今天有时间,来整理一下大致过程,记录一下代码。 整个监控引擎,简单来说,一是使用Quartz.Net实现多线程执行任务

gaiyi09的博客 2883

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Quartz动态改变任务时间

基于quartz-2.2 的动态任务调度 Quartz是一个完全由java编写的开源作业调度框架。 调度器 Quartz框架的核心是调度器。调度器负责管理Quartz应用运行时环境。调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件。Quartz不仅仅是线程和线程管理。为确保可伸缩性,Quartz采用了基于多线程的架构。启动时,框架初始化一套worker线程,这套线程被调度器用来执行预...

rui888的博客 8986

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Quartz 定时器动态修改执行时间修改后出现立即执行情况

问题描述 1,重点内容之前的提醒时间是 00 00 12 * * ? ,也就是12点提醒 2,在12点提醒了之后 在调用更新job时间表达式为 00 00 12 * * ?,也会立即提醒,当前的时间是12:01 ,也就是修改了立即执行 更新job时间表达式如下 解答如下 增加:withMisfireHandlingInstructionDoNothing()方法 1,不触发

zhouhao1256的专栏 7万+

Spring中配置Quartz的misfireInstruction

最近在做一个自动发送邮件的小功能,其中用到了Quartz来做事件触发。首先说一下,Quartz确实是个不错的开源项目,功能强大,配置灵活。在此就不在详述,喜欢的朋友可以去它的官方网站看文档和API:Quartz官方网站,站内也有许多介绍它如何配置使用的文章,多搜多搜,呵呵! 我这里邮件的重点是附件,所以确认附件的数据准确性很重要。所以当数据异常的时候,我们需要在任务执行的时间点之前将正在进行的任

george_hsu的专栏 1万+

Quartz入门——定时任务动态添加修改及持久化与自动恢复

这篇文章就带小伙伴们了解一下Quartz的基本使用。包括基本概念以及如何动态地的定时任务进行CRUD,并且如何实现定时任务的持久化以及任务恢复

Robod的博客 6945

Quartz.Net实现作业定时调度详解

Quartz.Net实现作业定时调度详解 原文:Quartz.Net实现作业定时调度详解 1、Quartz.NET介绍 Quartz.NET是一个强大、开源、轻量的作业调度框架,你能够用它来为执行一个作业而创建简单的或复杂的作业调度。它有很多特征,如:数据库支持,集群,插件,支持cron-like表达式等等。非常适合在平时的工作中,定时轮询...

weixin_30415113的博客 217

Quartz.net misfire实践

1.问题描述   在使用Quartz.net定时运行作业时,存在一种情况:作业错过了某次执行,当作业恢复的时候应该怎么处理?如:job1在3:50的时候应该执行的,但此刻job1处于暂停状态,而到3:55的时候,job1 resume,那么错过的3:50该怎么处理? 对此,Quartz.net使用misfire机制,misfire可以翻译为"错过了触发"。   2.misfire机制   这里以C...

weixin_34032621的博客 350

springBoot下使用quartz定时任务;动态修改任务执行时间

springBoot下使用quartz定时任务;动态修改任务执行时间

奔跑的菜鸡 3476

定时任务 创建

使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一、基于注解(@Scheduled) 二、基于接口(SchedulingConfigurer) 前者相信大家都很熟悉,但是实际使用中我们往往想从数据库中读取指定时间来动态执行定时任务,这时候基于接口的定时任务就派上用场了。 三、基于注解设定多线程定时任务 一、静态:基于注解 基于注解@Scheduled默认为单线程...

Sucker的小笔记 1004

c#quartz触发_C# Quartz.NET实现动态改变作业调度周期

Quartz:Java编写的开源的任务调度作业框架类似Timer之类定时执行的功能,但是更强大Quartz.NET:是把Quartz转成C#NuGet中可以直接下载对应类库官网:https://www.quartz-scheduler.net/主要对象:Job :工作,要执行的具体内容继承IJob。此接口中只有一个方法:execute(IJobExecutionContextcontext...

weixin_42536863的博客 857

Quartz 定时器动态创建任务和修改执行时间修改后出现立即执行情况

quartz在动态创建和修改触发器信息时,会触发立刻执行 按如下方法 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getJobExpression()).withMisfireHandlingInstructionDoNothing(); withMisfireHandlingInstr

liufei198613的博客 1万+

C#使用Quartz 实现定时任务

Quartz.net 简介 Quartz.net是一个强大、开源、轻量的作业调度框架,可以定时执行一个作业。 Quartz的基本组成部分 调度器:Scheduler 任务:JobDetail 触发器:Trigger,包括SimpleTrigger和CronTrigger 给计划者一个工作,让它在什么时间下执行这个工作。 任务的实现 将要定时执行的任务代码写到Ijob接口实现的Excute方法中,时间到后会自动执行这个任务。 Demo搭建 1.新建控制台应用程序,nuget添加对Quartz.net 的

无名指的约定 6157
上一篇: .NET Windows服务发布、安装、卸载、监听脚本。服务调试
下一篇: C# 去字符串首尾都好指定符号或字符 超简单方法
DayDay_Code
博客等级 码龄14年 31粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值