spring计划任务和spring批处理作业有什么区别 [英] What is the difference between spring scheduled tasks and spring batch jobs

查看:29
本文介绍了spring计划任务和spring批处理作业有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白 spring 中计划任务批处理作业之间的区别.我所说的计划任务是指配置如下的任务:

I dont understand the difference between scheduled tasks and batch jobs in spring. By scheduled tasks I mean the ones which are configured like these:

@EnableScheduling 
public class AppConfig{
..

并像使用

@Scheduled(fixedRate=550)
public void doSomething(){
..

我所说的批处理作业是指这些:

By batch jobs I mean these:

@EnableBatchProcessing
public class AppConfig{
..

以及许多实现,例如:作业作业启动器步骤ItemReaderItemWriter...等

and lots of implementations like: Jobs, Job launcher, Steps, ItemReader, ItemWriter... etc

我想知道除了实现差异之外它们之间的主要区别,而且我很好奇为什么要使用批处理作业并进行大量长时间的实现,而我们可以使用简单的计划任务.我的意思是计划作业的实现很容易,但根据批处理作业,它们可能有缺点吗?

I would like to know the main difference between them besides the implementation differences and also I am curious why to use batch jobs and make a lot of long implementations while we can use simple scheduled tasks. I mean the implementation of scheduled jobs is quite easy but maybe they had disadvantages according to the batch jobs?

推荐答案

我能想到的 2 个方面:afaik 当作业运行失败时,在 2. 运行中,它将以相同的作业参数运行..至少我认为你可以配置这个.和这种错误情况,您可以比手动在同一位置编写所有代码(您的预定方法)更容易配置这些错误情况.其次,当您还必须从某处读取数据并在某处写入时,批处理可能会为您的代码提供一个结构......批处理具有某种读取器、处理器、写入器模式......还有一些自动创建的数据库表(BATCH_JOB_INSTANCE)和批处理作业结果......比如作业开始时等......

2 aspects which i can think of: afaik when a job-run fails, in 2. run, it will run with the same job parameters.. at least you can configure this i think. and this kind of error situations which you can configure more easily than writing all in code in the same place manually (your scheduled method). Secondly, maybe batch gives a structure to your code when you also have to read your data from somewhere, and write somewhere... batch has some kind of reader, processor, writer schema.. Also some automatically created database tables (BATCH_JOB_INSTANCE) and batch job results.. like when the job started etc...

批处理的更多原因:大量数据、事务管理、基于块的处理、声明性 I/O、启动/停止/重启、重试/跳过、基于 Web 的管理界面.

More Reasons for a batch: large amount of data, Transaction management, Chunk based processing, Declarative I/O, Start/Stop/Restart, Retry/Skip, Web based administration interface.

这篇关于spring计划任务和spring批处理作业有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆