springbatch---->springbatch的使用(六)
前面的例子step都是线性的流程,这里我们提供一个非线性的流程,也就是根据不同的状态做不同的流程step处理。万一有天悔恨变得太现实太世故太麻木,说不定能从回忆中重拾随兴飞翔。
step非线性的流程
A step execution listener can change the exit status of a step. The job can then use the exit status for the transition decision to the next step。我们通过job传递参数来模拟不同的退出状态,从而来验证和加强非线性流程的学习。
一、在batch.xml中定义一个job
<!--一个非线性流程的job-->
<job id="noLinerJob">
<step id="firstStep">
<tasklet transaction-manager="transactionManager" ref="firstStepTasklet">
<listeners>
<listener ref="firstStepListener"/>
</listeners>
</tasklet>
<next on="COMPLETED" to="completedStep"/>
<next on="OWN STATUS" to="ownStatusStep"/>
<next on="*" to="allStatusStep"/>
</step>
<step id="completedStep">
<tasklet ref="completedTasklet"/>
</step>
<step id="ownStatusStep">
<tasklet ref="ownStatusTasklet"/>
</step>
<step id="allStatusStep">
<tasklet ref="allStatusTasklet"/>
</step>
</job>
在step层面上的监听器中会有不同的返回状态,根据不同的状态我们做不同的流程处理。比如如果是COMPLETED,我们就执行completedStep。如果是OWN STATUS(我们自定义的变量),就执行ownStatusStep。如果上述变量都没有,那么我们执行正则匹配所有的allStatusStep。下面我们列出firstStepListener的定义与实现。
<bean id="firstStepListener" class="spring.batch.noLiner.FirstStepListener" scope="step">
<property name="status" value="#{jobParameters['status']}"/>
</bean>
注意上述bean定义中的scope="step"是必须的,否则会报错。它的实现类代码如下
package spring.batch.noLiner; import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport; /**
* @Author: huhx
* @Date: 2017-11-02 下午 7:35
*/
public class FirstStepListener extends StepExecutionListenerSupport {
private String status; public void setStatus(String status) {
this.status = status;
} @Override
public ExitStatus afterStep(StepExecution stepExecution) {
if (status.equals("1")) {
return new ExitStatus("OWN STATUS");
} else if (status.equals("2")) {
return new ExitStatus("NO STATUS");
}
return ExitStatus.COMPLETED;
}
}
至于ownStatusTasklet和completedTasklet以及allStatusTasklet的实现比较简单,就是打印一句话。这里就不再列举。以下是打印的结果。
// 当sttus= != '1' && sttus= != '2'
first step tasklet.
completed status. // 当sttus='1'
first step tasklet.
own status. // 当sttus='2'
first step tasklet.
all status.
关于batch status与 exit status的区别:
Spring Batch uses two concepts to represent the status of an execution: the batch sta- tus and the exit status. Both step execution and job execution have their own batch and exit statuses property. The batch status describes the status of the execution of a job or a step. The exit status represents the status of the job/step once the execution is finished.
二、关于上述的next,springbatch还提供了fail、stop与end
fail、stop与end的用法如下所示
<step id="firstStep">
<tasklet transaction-manager="transactionManager" ref="firstStepTasklet">
<listeners>
<listener ref="firstStepListener"/>
</listeners>
</tasklet>
<next on="COMPLETED" to="completedStep"/>
<end on="OWN STATUS"/>
<fail on="*"/>
</step>
它们的说明如下

友情链接
springbatch---->springbatch的使用(六)的更多相关文章
- YII内置验证规则
required: 必填字段验证, 来自 CRequiredValidator类的别名 array(‘字段名列表用逗号隔开’, ‘required’), 就这样的一个小小的写法,可以让字段前面加 ...
- Spring Batch介绍
简介 SpringBatch 是一个大数据量的并行处理框架.通常用于数据的离线迁移,和数据处理,⽀持事务.并发.流程.监控.纵向和横向扩展,提供统⼀的接⼝管理和任务管理;SpringBatch是Spr ...
- SpringBoot整合SpringBatch
一.引入依赖 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&q ...
- 业务可视化-让你的流程图"Run"起来(6.定时任务&Spring-Batch的集成)
前言 首先,感谢大家对上一篇文章[业务可视化-让你的流程图"Run"起来(5.SpringBoot集成&微服务编排)]的支持. 分享一下近期我对这个项目的一些改进. 在项目 ...
- springbatch操作CSV文件
一.需求分析 使用Spring Batch对CSV文件进行读写操作: 读取一个含有四个字段的CSV文件(id, name, age, score), 对文件做简单的处理, 然后输出到还有一个csv文件 ...
- SpringBatch的核心组件JobLauncher和JobRepository
Spring Batch的框架包括启动批处理作业的组件和存储Job执行产生的元数据.因此只需掌握配置这个基础框架在批处理应用程序中即启动Jobs并存储Job元数据. 组件:Job Launcher和J ...
- SpringBatch简介
spring Batch是一个轻量级的.完善的批处理框架,旨在帮助企业建立健壮.高效的批处理应用.SpringBatch是Spring的一个子项目,使用Java语言并基于Spring框架为基础开发,使 ...
- spring-boot-oracle spring-batch
Install/Configure Oracle express Oracle xe installer for linux (I don't care if you're running linux ...
- springbatch的封装与使用
springbatch 主要实现批量数据的处理,我对batch进行的封装,提出了jobBase类型,具体job需要实现它即可.Spring Batch 不仅提供了统一的读写接口.丰富的任务处理方式.灵 ...
- SpringBatch的流程简介
SpringBatch的流程图如下: 每个Batch都会包含一个Job.Job就像一个容器,这个容器装了若干Step,Batch中实际干活的也就是这些Step,至于Step干什么活,无外乎读取数据,处 ...
随机推荐
- Windows10锁屏壁纸提取
CMD执行: %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\As ...
- 如何让Snippet Compiler 2008 支持linq
转载自:http://www.cnblogs.com/hbb0b0/archive/2009/09/01/1557832.html 注意,下面的图和上面的图,有些不同 上面是在 FileSystem ...
- 转载:手把手教你做iOS推送
手把手教你做iOS推送 http://www.cocoachina.com/industry/20130321/5862.html
- Console程序后台运行
[DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern IntPt ...
- 阿里云Redis开发规范[转]
一.键值设计 1. key名设计 (1)[建议]: 可读性和可管理性 以业务名(或数据库名)为前缀(防止key冲突),用冒号分隔,比如业务名:表名:id ugc:video:1 (2)[建议]:简洁性 ...
- 新建maven指定jdk版本-eclipse新建maven项目报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的解决方案
具体表现为: 使用Eclipse+Maven建立了一个Javaweb工程,JSP页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.Http ...
- 搭建交叉调试环境 arm-linux-gdb配合gdbserver
在嵌入式开发中,有时候需要进行源码级别的调试,可以设置断点,单步执行,相比于每步打印printf或者printk来说,更加友好.下面就来介绍这种调试方法. gdb交叉调试类似于网络浏览 ...
- 【玩转Golang】 通过组合嵌入实现代码复用
应用开发中的一个常见情景,为了避免简单重复,需要在基类中实现共用代码,着同样有助于后期维护. 如果在以往的支持类继承的语言中,比如c++,Java,c#等,这很简单!可是go不支持继承,只能mixin ...
- Java编程思想学习笔记——接口
1.抽象类和抽象方法 抽象方法:不完整的,仅有声明而没有方法体. abstract void f(); 抽象类:包含抽象方法的类.(若一个类包含一个或多个抽象方法,则该类必须限定为抽象的.) 1.用抽 ...
- 企业IT管理说:全自动就一定是最好的吗?
现如今,企业基础设施变得越来越网络化.虚拟化并且愈加复杂,人们更愿意寻求自动化以期优化信息管理过程.毕竟,有谁不想要一个更为有效且迅速的法子来管控数据的安全.存储.应用性能监控以及IT的经济性?这不用 ...