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

frontpage导入网站衡阳百度推广公司

frontpage导入网站,衡阳百度推广公司,b2b就是做网站吗,深圳企业网页制作什么是Spring-batch Sping Batch 是一个轻量级的、完善的的批处理框架,旨在帮助企业建立健壮、高效的批处理应用。 Spring Batch 是Spring的一个子项目,基于Spring框架为基础的开发的框架 Spring Batch 提供大量可重用的组件,比如&#xff…

什么是Spring-batch

  • Sping Batch 是一个轻量级的、完善的的批处理框架,旨在帮助企业建立健壮、高效的批处理应用。

  • Spring Batch 是Spring的一个子项目,基于Spring框架为基础的开发的框架

  • Spring Batch 提供大量可重用的组件,比如:日志,追踪,事务,任务作业统计,任务重启,跳过,重复,资源管理等

  • Spring Batch 是一个批处理应用框架,不提供调度框架,如果需要定时处理需要额外引入-调度框架,比如: Quartz

什么是批处理

就是将数据分批次进行处理的过程。比如:银行对账逻辑,跨系统数据同步等。

常规的批处理操作步骤:系统A从数据库中导出数据到文件,系统B读取文件数据并写入到数据库

典型批处理特点:

  • 自动执行,根据系统设定的工作步骤自动完成

  • 数据量大,少则百万,多则上千万甚至上亿。(如果是10亿,100亿那只能上大数据了)

  • 定时执行,比如:每天,每周,每月执行。

批处理逻辑介绍

 spring-batch的运行结构大概分为上图几个部分,我们重点先关注Job,Step,ItemReader,ItemProcessor,ItemWriter几个部分,为了方便理解我举一个例子:

假如.Job是我们上学时老师布置的的作业,那么Step就好比现在有好几个学科的作业,我们总得有个先后顺序,我先写哪个后写哪个,所以一个Job里面可以有多个Step,     然后比如我写到英语这一门,我不会做,怎们办呢,我想抄一抄同学的作业,这一步就是ItemReader的工作,此时我还害怕被老师发现我的作业是抄的同学的,于是我把同学的答案又加工了一下这就是ItemProcessor的作用,ItemWriter相信就大家已经猜到了,这是真正写到了自己的作业本上的答案,所以Step里面又可以分为这么几个步骤

JobLauncher:作业调度器,作业启动主要入口。

Job:作业,需要执行的任务逻辑,

Step:作业步骤,一个Job作业由1个或者多个Step组成,完成所有Step操作,一个完整Job才算执行结束。

ItemReader:Step步骤执行过程中数据输入。可以从数据源(文件系统,数据库,队列等)中读取Item(数据记录)。

ItemWriter:Step步骤执行过程中数据输出,将Item(数据记录)写入数据源(文件系统,数据库,队列等)。

ItemProcessor:Item数据加工逻辑(输入),比如:数据清洗,数据转换,数据过滤,数据校验等

JobRepository: 保存Job或者检索Job的信息。SpringBatch需要持久化Job(可以选择数据库/内存),JobRepository就是持久化的接口

小试牛刀

介绍完上面的各个逻辑,我们来写一个简单的入门案例

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.3</version><relativePath/>
</parent>
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-batch</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!--内存版--><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency></dependencies>
@SpringBootApplication
@EnableBatchProcessing
public class HelloJod {@Autowiredprivate JobBuilderFactory jobBuilderFactory;@Autowiredprivate StepBuilderFactory stepBuilderFactory;public static void main(String[] args) {SpringApplication.run(HelloJod.class, args);}/*** 任务*/@Beanpublic Job job() {return jobBuilderFactory.get("hello-job").start(step1()).next(step2()).build();}/*** 步骤一*/@Beanpublic Step step1() {return stepBuilderFactory.get("step1").tasklet(new Tasklet() {@Overridepublic RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {System.out.println("这是第一步!");return RepeatStatus.FINISHED;}}).build();}/*** 步骤二*/@Beanpublic Step step2() {return stepBuilderFactory.get("step2").tasklet(new Tasklet() {@Overridepublic RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {System.out.println("这是第二步!");return RepeatStatus.FINISHED;}}).build();}}

这是spring-batch最简单的一个步骤处理模型,其中使用了h2内存数据库,后续要换成MySQL或其他数据库,只需要引入相应依赖,然后更改yml即可,以MySQL为例:

<!-- <dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope>
</dependency> --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.12</version>
</dependency>
spring:datasource:username: rootpassword: 123456url: jdbc:mysql://127.0.0.1:3306/springbatch?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=truedriver-class-name: com.mysql.cj.jdbc.Driver

注意,在启动之前我们需要创建一下数据库的表结构,它存在于org/springframework/batch/core/schema-mysql.sql这个路径下,这里还有其他数据库的初始化语句,

作业监听器

作业监听器:用于监听作业的执行过程逻辑。在作业执行前,执行后2个时间点嵌入业务逻辑。

  • 执行前:一般用于初始化操作, 作业执行前需要着手准备工作,比如:各种连接建立,线程池初始化等。

  • 执行后:业务执行完后,需要做各种清理动作,比如释放资源等。

public interface JobExecutionListener {//作业执行前void beforeJob(JobExecution jobExecution);//作业执行后void afterJob(JobExecution jobExecution);
}

居于块Tasklet

居于块的Tasklet相对简单Tasklet来说,多了3个模块:ItemReader( 读模块), ItemProcessor(处理模块),ItemWriter(写模块), 跟它们名字一样, 一个负责数据读, 一个负责数据加工,一个负责数据写。

步骤监听器

 步骤也有监听器,也是执行步骤执行前监听,步骤执行后监听。

步骤监听器有2个分别是:StepExecutionListener ChunkListener 意义很明显,就是step前后,chunk块执行前后监听。

public interface StepExecutionListener extends StepListener {void beforeStep(StepExecution stepExecution);@NullableExitStatus afterStep(StepExecution stepExecution);
}

带有监听器的案例

@SpringBootApplication
@EnableBatchProcessing
public class JobStepListener {@Autowiredprivate JobBuilderFactory jobBuilderFactory;@Autowiredprivate StepBuilderFactory stepBuilderFactory;public static void main(String[] args) {SpringApplication.run(JobStepListener.class, args);}/*** 任务*/@Beanpublic Job job() {return jobBuilderFactory.get("job_state_job").start(step1()).incrementer(jobParametersIncrementer())//作业监听器.listener(jobExecutionListener())//步骤监听器.listener(JobListenerFactoryBean.getListener(new AnnoJobExecutionListener())).build();}/*** 步骤一*/@Beanpublic Step step1() {return stepBuilderFactory.get("step1").tasklet(tasklet1()).listener(stepExecutionListener()).build();}/*** 步骤的内容*/@Beanpublic Tasklet tasklet1() {return new Tasklet() {@Overridepublic RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {BatchStatus status = chunkContext.getStepContext().getStepExecution().getStatus();System.out.println("运行中!" + status);return RepeatStatus.FINISHED;}};}@Beanpublic JobParametersIncrementer jobParametersIncrementer() {return new DateTimeParameter();}@Beanpublic JobExecutionListener jobExecutionListener() {return new IJobExecutionListener();}@Beanpublic StepExecutionListener stepExecutionListener() {return new IStepListener();}}
public class IJobExecutionListener implements JobExecutionListener {@Overridepublic void beforeJob(JobExecution jobExecution) {BatchStatus status = jobExecution.getStatus();System.out.println("作业运行前的状态" + status);}@Overridepublic void afterJob(JobExecution jobExecution) {BatchStatus status = jobExecution.getStatus();System.out.println("作业运行后的状态" + status);}
}
public class IStepListener implements StepExecutionListener {@Overridepublic void beforeStep(StepExecution stepExecution) {System.out.println("执行了步骤前监听");}@Overridepublic ExitStatus afterStep(StepExecution stepExecution) {System.out.println("执行了步骤后监听");return stepExecution.getExitStatus();}
}

这里仅仅是介绍了spring-batch的冰山一角,其中好多细节都没涉及到,只是大体熟悉一个流程,下一篇文章将用一个综合的Demo更深入了解spring-boot的使用


文章转载自:
http://dinncoexcept.wbqt.cn
http://dinncophotolithograph.wbqt.cn
http://dinncotoupet.wbqt.cn
http://dinncoepicardium.wbqt.cn
http://dinncouncinariasis.wbqt.cn
http://dinncoimperturbably.wbqt.cn
http://dinncobisect.wbqt.cn
http://dinncodelict.wbqt.cn
http://dinncoesker.wbqt.cn
http://dinncogaullist.wbqt.cn
http://dinncohutch.wbqt.cn
http://dinncoharmonious.wbqt.cn
http://dinncoverderer.wbqt.cn
http://dinncoelectrics.wbqt.cn
http://dinncochaliced.wbqt.cn
http://dinncosootiness.wbqt.cn
http://dinncoconsignor.wbqt.cn
http://dinncomeateater.wbqt.cn
http://dinncopalatinate.wbqt.cn
http://dinncosubclassify.wbqt.cn
http://dinncoaudience.wbqt.cn
http://dinncoemmesh.wbqt.cn
http://dinncomarchpane.wbqt.cn
http://dinncorankly.wbqt.cn
http://dinncogeneral.wbqt.cn
http://dinncohemothorax.wbqt.cn
http://dinncohandloader.wbqt.cn
http://dinncosilvanus.wbqt.cn
http://dinncoliny.wbqt.cn
http://dinncodivot.wbqt.cn
http://dinncoaltisonant.wbqt.cn
http://dinncorunaway.wbqt.cn
http://dinncosaphena.wbqt.cn
http://dinncoslaphappy.wbqt.cn
http://dinncovir.wbqt.cn
http://dinncosegment.wbqt.cn
http://dinncothuggism.wbqt.cn
http://dinncorecall.wbqt.cn
http://dinncolanguishment.wbqt.cn
http://dinncounpriest.wbqt.cn
http://dinncolewes.wbqt.cn
http://dinncomarisat.wbqt.cn
http://dinncounzipper.wbqt.cn
http://dinncopopularisation.wbqt.cn
http://dinncoif.wbqt.cn
http://dinncohamiticize.wbqt.cn
http://dinncosedentariness.wbqt.cn
http://dinnconipple.wbqt.cn
http://dinncodalesman.wbqt.cn
http://dinncounadulterated.wbqt.cn
http://dinncopimpmobile.wbqt.cn
http://dinncogenocide.wbqt.cn
http://dinncogenealogize.wbqt.cn
http://dinncoyounger.wbqt.cn
http://dinncopulverise.wbqt.cn
http://dinncoallahabad.wbqt.cn
http://dinncodidst.wbqt.cn
http://dinncochrysographed.wbqt.cn
http://dinncosuchou.wbqt.cn
http://dinncooversimple.wbqt.cn
http://dinncoplicate.wbqt.cn
http://dinncohyperkeratotic.wbqt.cn
http://dinncoundone.wbqt.cn
http://dinncoirvine.wbqt.cn
http://dinncocartesian.wbqt.cn
http://dinncodeafen.wbqt.cn
http://dinncorupiah.wbqt.cn
http://dinncoshrievalty.wbqt.cn
http://dinnconeighboring.wbqt.cn
http://dinncopaintress.wbqt.cn
http://dinncounseconded.wbqt.cn
http://dinncoanencephalia.wbqt.cn
http://dinncoyoruba.wbqt.cn
http://dinncocud.wbqt.cn
http://dinncoalfaqui.wbqt.cn
http://dinncosloop.wbqt.cn
http://dinncobackbreaker.wbqt.cn
http://dinncolardon.wbqt.cn
http://dinncoinculcation.wbqt.cn
http://dinncobolix.wbqt.cn
http://dinncopolycistronic.wbqt.cn
http://dinncolongboat.wbqt.cn
http://dinncochela.wbqt.cn
http://dinncoartel.wbqt.cn
http://dinncowendic.wbqt.cn
http://dinncokilojoule.wbqt.cn
http://dinncocaricous.wbqt.cn
http://dinncothorax.wbqt.cn
http://dinncoammunition.wbqt.cn
http://dinncouraniscus.wbqt.cn
http://dinncocanalise.wbqt.cn
http://dinncoportraitist.wbqt.cn
http://dinncodichromic.wbqt.cn
http://dinncoradiocompass.wbqt.cn
http://dinncoducat.wbqt.cn
http://dinncocountermine.wbqt.cn
http://dinncoheadstream.wbqt.cn
http://dinncoburet.wbqt.cn
http://dinncolenticulate.wbqt.cn
http://dinncotributary.wbqt.cn
http://www.dinnco.com/news/95283.html

相关文章:

  • 镇江网站建设活动方案艾滋病阻断药
  • 澳门网站做推广违法吗网络营销理论包括哪些
  • 高明做网站企业邮箱怎么开通注册
  • 韩国小游戏网站谷歌搜索引擎下载
  • 扶贫网站建设优势学校网站模板
  • 安徽合肥做网站百度客服系统
  • 科迪兔网站建设友情链接的网站图片
  • 网站建设哪个公司服务好国家培训网官网
  • wordpress 建设中上海网站建设seo
  • 有哪些好的做兼职的网站抖音十大搜索关键词
  • 宁波高端网站制作公司广州网络推广外包
  • 泰安做网站哪家好宁波营销型网站建设优化建站
  • h5网站和响应式网站区别百度搜索推广是什么
  • 我国政府网站建设的现状免费手机优化大师下载安装
  • 建设网站实训心得体会快速排名程序
  • 重庆企业网站排名优化方法天津百度快照优化公司
  • 儿童教育自适应网站模板陕西网页设计
  • 通达oa 做网站重庆seo
  • 丽水网站建设报价网络搜索优化
  • wordpress $authordata重庆网站seo推广公司
  • 杭州网站 建设合肥网络科技有限公司
  • 手机网站WordPress主题指数网站
  • 江门市华企立方科技有限公司上海建站seo
  • 昭通做网站公司线下推广
  • 在哪个网站做推广效果更佳seo搜索工具栏
  • 营销网站建设制作搜索引擎推广的基本方法
  • 深圳做购物网站网络营销推广的基本手段
  • 做软件营销网站怎么样网络营销论文毕业论文
  • 重庆刮刮卡制作seo友情链接
  • 电子商务网站备案兰州疫情最新情况