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

天津哪家公司做公司网站常宁市城乡和住房建设网站

天津哪家公司做公司网站,常宁市城乡和住房建设网站,阿里云备案 网站名称,龙岩做网站推广​ 博客主页: 南来_北往 系列专栏#xff1a;Spring Boot实战 前言 最近一周#xff0c;被借调到其他部门#xff0c;赶一个紧急需求#xff0c;需求内容如下#xff1a; PC网页触发一条设备升级记录#xff08;下图#xff09;#xff0c;后台要定时批量设备更… ​ 博客主页:     南来_北往 系列专栏Spring Boot实战 前言 最近一周被借调到其他部门赶一个紧急需求需求内容如下 PC网页触发一条设备升级记录下图后台要定时批量设备更新。这里定时要用到Quartz批量数据处理要用到SpringBatch二者结合可以完成该需求。 由于之前没有用过SpringBatch于是上网查了下资料发现可参考的不是很多于是只能去慢慢的翻看官方文档。 Spring Batch - Reference Documentation 具体实现 在你的pom.xml文件中添加以下依赖  dependencies!-- Spring Boot --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-batch/artifactId/dependency!-- Quartz --dependencygroupIdorg.quartz-scheduler/groupIdartifactIdquartz/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-quartz/artifactId/dependency /dependencies在application.properties文件中添加以下配置 spring.quartz.job-store-typememory spring.quartz.properties.org.quartz.scheduler.instanceNameMyScheduler spring.quartz.properties.org.quartz.threadPool.threadCount5创建一个实现Job接口的类例如MyBatchJob import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.quartz.QuartzJobBean;public class MyBatchJob extends QuartzJobBean {Autowiredprivate JobLauncher jobLauncher;Overrideprotected void executeInternal(JobExecutionContext context) throws JobExecutionException {try {jobLauncher.run(myBatchJob(), new JobParametersBuilder().addString(JobID, String.valueOf(System.currentTimeMillis())).toJobParameters());} catch (Exception e) {throw new JobExecutionException(e);}}private Job myBatchJob() {// 返回你的Spring Batch Job实例} }在你的配置类中例如ApplicationConfig添加一个SchedulerFactoryBean的Bean用于配置定时任务的触发器 import org.quartz.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.quartz.SchedulerFactoryBean;Configuration public class ApplicationConfig {Beanpublic JobDetail myBatchJobDetail() {return JobBuilder.newJob(MyBatchJob.class).withIdentity(myBatchJob).storeDurably().build();}Beanpublic Trigger myBatchJobTrigger() {SimpleScheduleBuilder scheduleBuilder SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60) // 设置任务执行间隔例如每60秒执行一次.repeatForever(); // 设置任务重复执行return TriggerBuilder.newTrigger().forJob(myBatchJobDetail()).withIdentity(myBatchJobTrigger).withSchedule(scheduleBuilder).build();}Beanpublic SchedulerFactoryBean schedulerFactoryBean() {SchedulerFactoryBean schedulerFactoryBean new SchedulerFactoryBean();schedulerFactoryBean.setJobDetails(myBatchJobDetail());schedulerFactoryBean.setTriggers(myBatchJobTrigger());return schedulerFactoryBean;} }现在你已经成功地整合了Spring Boot、Spring Batch和Quartz实现了定时批量任务。每隔指定的时间间隔例如60秒MyBatchJob将会被执行一次。
http://www.hkea.cn/news/14320039/

相关文章:

  • 电子商务类网站有哪些监利县建设局网站
  • 免费网站搭建平台wordpress 笔记插件下载
  • 成都建设网站 scgckjwordpress id3
  • 网站如何做分享开县做网站
  • 苏州微网站开发天眼企业查询系统
  • 昌吉建设局网站常用的博客建站程序
  • 网页建设与网站设计临清网站制作
  • 自己做网站如何盈利2023新闻摘抄10条
  • 网站开发团队组成东莞市建设小学网站
  • 响应式自适应网站雄安智能网站建设电话
  • 呼市做网站公司wordpress 下载中心插件
  • 网页设计小白做网站3小时网站建设平台
  • 在线做原型的网站手机网站特效
  • 培训机构网站如何建设wdcp网站迁移
  • 如何免费做网站推广的推广软件平台
  • 食品网站建设建议凡度网络北京网站建设公司
  • 做网站需要提供些什么页面四川省建设建设监理协会网站
  • app网站开发长沙比亚迪新能源车型及价格
  • 哈巴河网站制作网页制作网站首页设计
  • 电子产品商务网站模板简单手工
  • 微网站建设加盟多页网站制作
  • 北京网站开发公司电话外链网址
  • 孝义网站建设长沙网站排名系统
  • 个人主页建站百度手机助手安卓版下载
  • 用户体验好的网站济南槐荫区做网站的
  • 做网站的前景网站建设面试题
  • 一流的聊城做网站费用互联网推广渠道
  • app优化网站外包兼职做图的网站
  • 企业网站能提供哪些服务汉中杨海明
  • 做美食视频网站有哪些商标购买在哪个平台好