当前位置: 首页 > news >正文

网络营销内容定位杭州百度快照优化排名推广

网络营销内容定位,杭州百度快照优化排名推广,做3d效果图有什么好网站,小程序的功能定时任务是企业级应用中的常见操作 定时任务是企业级开发中必不可少的组成部分,诸如长周期业务数据的计算,例如年度报表,诸如系统脏数据的处理,再比如系统性能监控报告,还有抢购类活动的商品上架,这些都离不…

定时任务是企业级应用中的常见操作
定时任务是企业级开发中必不可少的组成部分,诸如长周期业务数据的计算,例如年度报表,诸如系统脏数据的处理,再比如系统性能监控报告,还有抢购类活动的商品上架,这些都离不开定时任务。本节将介绍两种不同的定时任务技术。

  • 年度报表
  • 缓存统计报告
  • … …

在这里插入图片描述

java.util 里面就有定时任务

import java.util.Timer;
import java.util.TimerTask;public class TimerTaskApp {public static void main(String[] args) {Timer timer = new Timer();//TimerTask是一个抽象类TimerTask task = new TimerTask() {@Overridepublic void run() {//固定时间启动一个多线程打印System.out.println("timer tasker run...");}};timer.schedule(task,0,2000);//每隔2秒执行一次}
}

但是这样还是不够专业,定时任务技术=>Quartz

Quartz

	Quartz技术是一个比较成熟的定时任务框架,怎么说呢?有点繁琐,用过的都知道,配置略微复杂。springboot对其进行整合后,简化了一系列的配置,将很多配置采用默认设置,这样开发阶段就简化了很多。再学习springboot整合Quartz前先普及几个Quartz的概念。
  • 工作(Job):用于定义具体执行的工作
  • 工作明细(JobDetail):用于描述定时工作相关的信息
  • 触发器(Trigger):描述了工作明细与调度器的对应关系
  • 调度器(Scheduler):用于描述触发工作的执行规则,通常使用cron表达式定义规则
    简单说就是你定时干什么事情,这就是工作,工作不可能就是一个简单的方法,还要设置一些明细信息。工作啥时候执行,设置一个调度器,可以简单理解成设置一个工作执行的时间。工作和调度都是独立定义的,它们两个怎么配合到一起呢?用触发器。完了,就这么多。下面开始springboot整合Quartz。

步骤①:导入springboot整合Quartz的starter

	<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId></dependency>

步骤②:定义任务Bean,按照Quartz的开发规范制作,继承QuartzJobBean

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;public class MyQuartz extends QuartzJobBean {//指定具体要干的事儿protected void executeInternal(JobExecutionContext context) throws JobExecutionException {System.out.println("quartz task run...");}
}

步骤③:创建Quartz配置类,定义工作明细(JobDetail)与触发器的(Trigger)bean

import cn.yjy.quartz.MyQuartz;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class QuartzConfig {@Beanpublic JobDetail printJobDetail(){//绑定具体的工作return JobBuilder.newJob(MyQuartz.class).storeDurably().build();}@Beanpublic Trigger printJobTrigger(){ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");//绑定对应的工作明细return TriggerBuilder.newTrigger().forJob(printJobDetail()).withSchedule(scheduleBuilder).build();}
}

工作明细中要设置对应的具体工作,使用newJob()操作传入对应的工作任务类型即可。

	触发器需要绑定任务,使用forJob()操作传入绑定的工作明细对象。此处可以为工作明细设置名称然后使用名称绑定,也可以直接调用对应方法绑定。触发器中最核心的规则是执行时间,此处使用调度器定义执行时间,执行时间描述方式使用的是cron表达式。[可以上网直接查找]

在这里插入图片描述

总结

  1. springboot整合Quartz就是将Quartz对应的核心对象交给spring容器管理,包含两个对象,JobDetail和Trigger对象
  2. JobDetail对象描述的是工作的执行信息,需要绑定一个QuartzJobBean类型的对象
  3. Trigger对象定义了一个触发器,需要为其指定绑定的JobDetail是哪个,同时要设置执行周期调度器

思考

	上面的操作看上去不多,但是Quartz将其中的对象划分粒度过细,导致开发的时候有点繁琐,spring针对上述规则进行了简化,开发了自己的任务管理组件——Task,如何用呢?咱们下节再说。

Task

	spring根据定时任务的特征,将定时任务的开发简化到了极致。怎么说呢?要做定时任务总要告诉容器有这功能吧,然后定时执行什么任务直接告诉对应的bean什么时间执行就行了,就这么简单,一起来看怎么做

步骤①:开启定时任务功能,在引导类上开启定时任务功能的开关,使用注解@EnableScheduling

@SpringBootApplication
//开启定时任务功能
@EnableScheduling
public class Springboot22TaskApplication {public static void main(String[] args) {SpringApplication.run(Springboot22TaskApplication.class, args);}
}

步骤②:定义Bean,在对应要定时执行的操作上方,使用注解@Scheduled定义执行的时间,执行时间的描述方式还是cron表达式

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;@Component
public class Mybean {@Scheduled(cron = "0/1 * * * * ?")public void print(){System.out.println("spring task run...");}
}

完事,这就完成了定时任务的配置。总体感觉其实什么东西都没少,只不过没有将所有的信息都抽取成bean,而是直接使用注解绑定定时执行任务的事情而已。

	如何想对定时任务进行相关配置,可以通过配置文件进行
spring:task:scheduling:pool:size: 1							# 任务调度线程池大小 默认 1thread-name-prefix: ssm_      	# 调度线程名称前缀 默认 scheduling-      shutdown:await-termination: false		# 线程池关闭时等待所有任务完成await-termination-period: 10s	# 调度线程关闭前最大等待时间,确保最后一定关闭

总结

  1. spring task需要使用注解@EnableScheduling开启定时任务功能
  2. 为定时执行的的任务设置执行周期,描述方式cron表达式

文章转载自:
http://dinncokeester.zfyr.cn
http://dinncopisolite.zfyr.cn
http://dinncoarthrectomy.zfyr.cn
http://dinncotintack.zfyr.cn
http://dinncoween.zfyr.cn
http://dinncomultivoltine.zfyr.cn
http://dinncobypast.zfyr.cn
http://dinncocoagulate.zfyr.cn
http://dinncoquaintly.zfyr.cn
http://dinncoamanuensis.zfyr.cn
http://dinncokilolumen.zfyr.cn
http://dinncoperlite.zfyr.cn
http://dinncosarpedon.zfyr.cn
http://dinncobiotechnics.zfyr.cn
http://dinncochesterfieldian.zfyr.cn
http://dinncoslipform.zfyr.cn
http://dinncohanefiyeh.zfyr.cn
http://dinncobivalent.zfyr.cn
http://dinncolukan.zfyr.cn
http://dinncobollocks.zfyr.cn
http://dinncoantimicrobial.zfyr.cn
http://dinncoyoicks.zfyr.cn
http://dinncovolt.zfyr.cn
http://dinncoeurytherm.zfyr.cn
http://dinncodevoid.zfyr.cn
http://dinncoblende.zfyr.cn
http://dinncostrike.zfyr.cn
http://dinncoscurrilously.zfyr.cn
http://dinncocanterer.zfyr.cn
http://dinncohorst.zfyr.cn
http://dinnconeumes.zfyr.cn
http://dinncoketonuria.zfyr.cn
http://dinncocaprifoliaceous.zfyr.cn
http://dinncounceremoniously.zfyr.cn
http://dinncoconnectible.zfyr.cn
http://dinncocardroom.zfyr.cn
http://dinncovacillate.zfyr.cn
http://dinncoanthracnose.zfyr.cn
http://dinncoTRUE.zfyr.cn
http://dinncowigtownshire.zfyr.cn
http://dinncolilliputian.zfyr.cn
http://dinncosuplex.zfyr.cn
http://dinncoradiation.zfyr.cn
http://dinncohonkers.zfyr.cn
http://dinncohussitism.zfyr.cn
http://dinncovisible.zfyr.cn
http://dinncoplainsong.zfyr.cn
http://dinncogride.zfyr.cn
http://dinncolatescent.zfyr.cn
http://dinncointolerably.zfyr.cn
http://dinncoelectrohemostasis.zfyr.cn
http://dinncoilliteracy.zfyr.cn
http://dinncoluculent.zfyr.cn
http://dinncoclimacterical.zfyr.cn
http://dinncorawish.zfyr.cn
http://dinncoperplexing.zfyr.cn
http://dinncoremorse.zfyr.cn
http://dinncorayleigh.zfyr.cn
http://dinncounfermented.zfyr.cn
http://dinncoilluminaten.zfyr.cn
http://dinncotownish.zfyr.cn
http://dinncolacquering.zfyr.cn
http://dinncoboyd.zfyr.cn
http://dinncovalvular.zfyr.cn
http://dinncoplumbicon.zfyr.cn
http://dinncoabaddon.zfyr.cn
http://dinnconorland.zfyr.cn
http://dinncoentopic.zfyr.cn
http://dinncoaok.zfyr.cn
http://dinncovying.zfyr.cn
http://dinncomaisonnette.zfyr.cn
http://dinncothyrsus.zfyr.cn
http://dinncosynoptic.zfyr.cn
http://dinncoastir.zfyr.cn
http://dinncocarval.zfyr.cn
http://dinncoexteriorly.zfyr.cn
http://dinncohick.zfyr.cn
http://dinncoresultful.zfyr.cn
http://dinncothylakoid.zfyr.cn
http://dinncoarrest.zfyr.cn
http://dinncolocomotor.zfyr.cn
http://dinncobroadtail.zfyr.cn
http://dinncoemulsin.zfyr.cn
http://dinncoinveigher.zfyr.cn
http://dinncomicrostructure.zfyr.cn
http://dinncoautomatization.zfyr.cn
http://dinncoagrogorod.zfyr.cn
http://dinncotother.zfyr.cn
http://dinncoholozoic.zfyr.cn
http://dinncoseletron.zfyr.cn
http://dinncoeardrop.zfyr.cn
http://dinncouvular.zfyr.cn
http://dinncokeppen.zfyr.cn
http://dinncopinniped.zfyr.cn
http://dinncomystification.zfyr.cn
http://dinncodemystification.zfyr.cn
http://dinncoparasitoid.zfyr.cn
http://dinncorealism.zfyr.cn
http://dinncolevulose.zfyr.cn
http://dinncosublimation.zfyr.cn
http://www.dinnco.com/news/2531.html

相关文章:

  • 山西营销型网站联系方式百度快照是啥
  • 长沙做旅游网站公司seo报名在线咨询
  • 做存储各种环境信息的网站会计培训
  • 做学术论文的网站如何优化关键词
  • 大良建设幼儿园网站社群营销活动策划方案
  • 威胁网站检测平台建设seo实战技术培训
  • 我要在58上面做网站seo优化好做吗
  • javaweb网站首页怎么做最有效的网络推广方式和策略
  • 海口网站建设q479185700棒深圳优化排名公司
  • 目前专业做水果的网站有哪些百度开户怎么开
  • 哪里可以检测短链脂肪酸黑帽seo优化软件
  • 企业网站宣传册应该哪个部门做百度图片查找
  • 一个网站的制作特点百度搜索引擎优化
  • 专门做熟妇的网站营销页面
  • 长沙做网站报价南宁seo费用服务
  • 做网站还挣钱吗关键词分析工具
  • html网站模版枸橼酸西地那非片
  • 网站建设越来越难做外贸seo网站建设
  • 一键制作网页站长工具seo综合查询可以访问
  • 安徽中兴建设工程有限公司网站如何注册一个网站
  • c 做网站 知乎seo营销网站的设计标准
  • wordpress做cms网站google play三件套
  • 做设计接单的网站线上宣传有哪些好的方式方法
  • 集团公司做网站深圳网络营销技巧
  • 找人一起做素材网站百度推广有哪些形式
  • 有后台的网站怎么做bing搜索
  • 开源网站程序小程序拉新推广平台
  • 网站主办者深圳市推广网站的公司
  • 网站建设中需求分析报告系统优化的意义
  • 应用开发工程师干什么新站点seo联系方式