Spring Batch中面向TaskletStep的处理

许多企业应用程序需要批处理才能每天处理数十亿笔交易。 必须处理这些大事务集,而不会出现性能问题。 Spring Batch是一个轻量级且强大的批处理框架,用于处理这些大数据集。

Spring Batch提供了“面向TaskletStep”和“面向块”的处理风格。 在本文中,解释了面向TaskletStep的处理模型。

让我们研究基本的Spring Batch组件:

职位:

封装整个批处理过程的实体。 步骤和任务集在作业下定义

步 :

封装批处理作业的独立顺序阶段的域对象。

JobInstance:

批处理域对象代表一个唯一可识别的作业运行-它的标识由Job和JobParameters对提供。

JobParameters:

值对象,代表批处理作业的运行时参数。

工作执行:

JobExecution指的是一次尝试运行Job的技术概念。 执行可能以失败或成功结束,但是与给定执行相对应的JobInstance不会被视为完成,除非执行成功完成。

JobRepository:

一个接口,负责批处理元数据实体的持久性。 在以下示例中,通过MapJobRepositoryFactoryBean使用内存中的存储库。

JobLauncher:

公开运行方法的接口,该方法启动并控制定义的作业。

TaskLet:

暴露执行方法的接口,该方法将被反复调用,直到它返回RepeatStatus.FINISHED或引发异常以指示失败。 当以下示例不要求读者和作家时使用它。

让我们看一下如何开发面向Tasklet步骤的处理模型。

二手技术:

  • JDK 1.7.0_09
  • Spring3.1.3
  • Spring批次2.1.9
  • Maven的3.0.4

步骤1:建立已完成的专案

创建一个Maven项目,如下所示。 (可以使用Maven或IDE插件来创建它)。

步骤2:图书馆

首先,将依赖项添加到Maven的pom.xml中。

<properties><spring.version>3.1.3.RELEASE</spring.version><spring-batch.version>2.1.9.RELEASE</spring-batch.version></properties><dependencies><!-- Spring Dependencies --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency>    <!-- Spring Batch Dependency --><dependency><groupId>org.springframework.batch</groupId><artifactId>spring-batch-core</artifactId><version>${spring-batch.version}</version></dependency><!-- Log4j library --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.16</version></dependency></dependencies>

maven-compiler-plugin (Maven插件)用于使用JDK 1.7编译项目

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.0</version><configuration><source>1.7</source><target>1.7</target></configuration></plugin>

以下Maven插件可用于创建runnable-jar

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.0</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><configuration><source>1.7</source><target>1.7</target></configuration><transformers><transformerimplementation='org.apache.maven.plugins.shade.resource.ManifestResourceTransformer'><mainClass>com.onlinetechvision.exe.Application</mainClass></transformer><transformerimplementation='org.apache.maven.plugins.shade.resource.AppendingTransformer'><resource>META-INF/spring.handlers</resource></transformer><transformerimplementation='org.apache.maven.plugins.shade.resource.AppendingTransformer'><resource>META-INF/spring.schemas</resource></transformer></transformers></configuration></execution></executions></plugin>

步骤3:创建成功的StepTasklet任务表

通过实现Tasklet接口来创建SuccessStepTasklet。 它成功地说明了业务逻辑。

package com.onlinetechvision.tasklet;import org.apache.log4j.Logger;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;/*** SuccessfulStepTasklet Class illustrates a successful job** @author onlinetechvision.com* @since 27 Nov 2012* @version 1.0.0**/
public class SuccessfulStepTasklet implements Tasklet {private static final Logger logger = Logger.getLogger(SuccessfulStepTasklet.class);private String taskResult;/*** Executes SuccessfulStepTasklet** @param StepContribution stepContribution* @param ChunkContext chunkContext* @return RepeatStatus* @throws Exception**/@Overridepublic RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {logger.debug('Task Result : ' + getTaskResult());return RepeatStatus.FINISHED;}public String getTaskResult() {return taskResult;}public void setTaskResult(String taskResult) {this.taskResult = taskResult;} }

步骤4:创建失败的StepTasklet任务

通过实现Tasklet接口创建FailedStepTasklet。 它说明了失败步骤中的业务逻辑。

package com.onlinetechvision.tasklet;import org.apache.log4j.Logger;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;/*** FailedStepTasklet Class illustrates a failed job.** @author onlinetechvision.com* @since 27 Nov 2012* @version 1.0.0**/
public class FailedStepTasklet implements Tasklet {private static final Logger logger = Logger.getLogger(FailedStepTasklet.class);private String taskResult;/*** Executes FailedStepTasklet** @param StepContribution stepContribution* @param ChunkContext chunkContext* @return RepeatStatus* @throws Exception**/@Overridepublic RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {logger.debug('Task Result : ' + getTaskResult());throw new Exception('Error occurred!');}public String getTaskResult() {return taskResult;}public void setTaskResult(String taskResult) {this.taskResult = taskResult;} }

步骤5:创建BatchProcessStarter类

创建BatchProcessStarter类以启动作业。 此外,它记录他们的执行结果。 无法使用相同的参数重新启动已完成的作业实例,因为该作业实例已经存在于作业存储库中,并且JobInstanceAlreadyCompleteException抛出并带有“作业实例已经存在且已完成”说明。 可以使用其他参数重新启动。 在以下示例中,设置了不同的currentTime参数以重新启动FirstJob。

package com.onlinetechvision.spring.batch;import org.apache.log4j.Logger;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;/*** BatchProcessStarter Class launches the jobs and logs their execution results.** @author onlinetechvision.com* @since 27 Nov 2012* @version 1.0.0**/
public class BatchProcessStarter {private static final Logger logger = Logger.getLogger(BatchProcessStarter.class);private Job firstJob;private Job secondJob;private Job thirdJob;private JobLauncher jobLauncher;private JobRepository jobRepository;/*** Starts the jobs and logs their execution results.**/public void start() {JobExecution jobExecution = null;JobParametersBuilder builder = new JobParametersBuilder();try {builder.addLong('currentTime', new Long(System.currentTimeMillis()));getJobLauncher().run(getFirstJob(), builder.toJobParameters());jobExecution = getJobRepository().getLastJobExecution(getFirstJob().getName(), builder.toJobParameters());logger.debug(jobExecution.toString());			getJobLauncher().run(getSecondJob(), builder.toJobParameters());jobExecution = getJobRepository().getLastJobExecution(getSecondJob().getName(), builder.toJobParameters());logger.debug(jobExecution.toString());getJobLauncher().run(getThirdJob(), builder.toJobParameters());jobExecution = getJobRepository().getLastJobExecution(getThirdJob().getName(), builder.toJobParameters());logger.debug(jobExecution.toString());builder.addLong('currentTime', new Long(System.currentTimeMillis()));getJobLauncher().run(getFirstJob(), builder.toJobParameters());jobExecution = getJobRepository().getLastJobExecution(getFirstJob().getName(), builder.toJobParameters());logger.debug(jobExecution.toString());} catch (JobExecutionAlreadyRunningException| JobRestartException| JobInstanceAlreadyCompleteException| JobParametersInvalidException e) {logger.error(e);}}	public Job getFirstJob() {return firstJob;}public void setFirstJob(Job firstJob) {this.firstJob = firstJob;}public Job getSecondJob() {return secondJob;}public void setSecondJob(Job secondJob) {this.secondJob = secondJob;}	public Job getThirdJob() {return thirdJob;}public void setThirdJob(Job thirdJob) {this.thirdJob = thirdJob;}public JobLauncher getJobLauncher() {return jobLauncher;}public void setJobLauncher(JobLauncher jobLauncher) {this.jobLauncher = jobLauncher;}public JobRepository getJobRepository() {return jobRepository;}public void setJobRepository(JobRepository jobRepository) {this.jobRepository = jobRepository;}	}

步骤6:创建applicationContext.xml

Spring配置文件applicationContext.xml已创建。 它涵盖了Tasklet和BatchProcessStarter定义。

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns='http://www.springframework.org/schema/beans'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns:batch='http://www.springframework.org/schema/batch'xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/batchhttp://www.springframework.org/schema/batch/spring-batch-2.1.xsd'><bean id='firstTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='First Task is executed...' /></bean><bean id='secondTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Second Task is executed...' /></bean><bean id='thirdTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Third Task is executed...' /></bean><bean id='fourthTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Fourth Task is executed...' /></bean><bean id='fifthTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Fifth Task is executed...' /></bean><bean id='sixthTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Sixth Task is executed...' /></bean><bean id='seventhTasklet' class='com.onlinetechvision.tasklet.SuccessfulStepTasklet'><property name='taskResult'  value='Seventh Task is executed...' /></bean><bean id='failedStepTasklet' class='com.onlinetechvision.tasklet.FailedStepTasklet'><property name='taskResult'  value='Error occurred!' /></bean>    <bean id='batchProcessStarter' class='com.onlinetechvision.spring.batch.BatchProcessStarter'><property name='jobLauncher' ref='jobLauncher'/><property name='jobRepository' ref='jobRepository'/><property name='firstJob' ref='firstJob'/><property name='secondJob' ref='secondJob'/><property name='thirdJob' ref='thirdJob'/></bean>    </beans>

步骤7:创建jobContext.xml

Spring配置文件jobContext.xml已创建。 乔布斯的流程如下:

FirstJob的流程:

1)开始第一步。
2)FirstStep以COMPLETED状态完成后,SecondStep开始。
3)SecondStep以COMPLETED状态完成后,将启动ThirdStep。 4)在以COMPLETED状态完成ThirdStep之后,以COMPLETED状态完成FirstJob执行。

SecondJob的流程:

1)第四步开始。
2)在以COMPLETED状态完成第四步之后,开始第五步。
3)在完成状态为FifthStep之后,以完成状态完成SecondJob执行。

ThirdJob的流程:

1)第六步开始。
2)在完成状态为SixthStep之后,将启动SeventhStep。
3)在SeventhStep以FAILED状态完成后,ThirdJob执行在FAILED状态下完成。

FirstJob的流程与第一次执行相同。

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns='http://www.springframework.org/schema/beans'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns:batch='http://www.springframework.org/schema/batch'xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/batchhttp://www.springframework.org/schema/batch/spring-batch-2.1.xsd'><import resource='applicationContext.xml'/><bean id='transactionManager' class='org.springframework.batch.support.transaction.ResourcelessTransactionManager'/><bean id='jobRepository' class='org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean'><property name='transactionManager' ref='transactionManager' /></bean><bean id='jobLauncher' class='org.springframework.batch.core.launch.support.SimpleJobLauncher' ><property name='jobRepository' ref='jobRepository'/></bean><bean id='taskletStep' class='org.springframework.batch.core.step.tasklet.TaskletStep'><property name='jobRepository' ref='jobRepository'/><property name='transactionManager' ref='transactionManager'/></bean><batch:job id='firstJob'><batch:step id='firstStep' next='secondStep'><batch:tasklet ref='firstTasklet'/></batch:step><batch:step id='secondStep' next='thirdStep' ><batch:tasklet ref='secondTasklet'/></batch:step><batch:step id='thirdStep'><batch:tasklet ref='thirdTasklet' /></batch:step></batch:job><batch:job id='secondJob'><batch:step id='fourthStep'><batch:tasklet ref='fourthTasklet' /><batch:next on='*' to='fifthStep' /><batch:next on='FAILED' to='failedStep' /></batch:step><batch:step id='fifthStep'><batch:tasklet ref='fifthTasklet' /></batch:step><batch:step id='failedStep'><batch:tasklet ref='failedStepTasklet' /></batch:step></batch:job><batch:job id='thirdJob'><batch:step id='sixthStep'><batch:tasklet ref='sixthTasklet' /><batch:next on='*' to='seventhStep' /><batch:next on='FAILED' to='eighthStep' /></batch:step><batch:step id='seventhStep'><batch:tasklet ref='failedStepTasklet' /></batch:step><batch:step id='eighthStep'><batch:tasklet ref='seventhTasklet' /></batch:step></batch:job></beans>

步骤8:建立应用程式类别

创建应用程序类以运行应用程序。

package com.onlinetechvision.exe;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.onlinetechvision.spring.batch.BatchProcessStarter;/*** Application Class starts the application.** @author onlinetechvision.com* @since 27 Nov 2012* @version 1.0.0**/
public class Application {/*** Starts the application** @param  String[] args**/public static void main(String[] args) {ApplicationContext appContext = new ClassPathXmlApplicationContext('jobContext.xml');BatchProcessStarter batchProcessStarter = (BatchProcessStarter)appContext.getBean('batchProcessStarter');batchProcessStarter.start();}}

步骤9:建立专案

构建OTV_SpringBatch_TaskletStep_Oriented_Processing项目后,将创建OTV_SpringBatch_TaskletStep-0.0.1-SNAPSHOT.jar

步骤10:运行项目

运行创建的OTV_SpringBatch_TaskletStep-0.0.1-SNAPSHOT.jar文件后,将显示以下控制台输出日志:

First Job的控制台输出:

25.11.2012 21:29:19  INFO (SimpleJobLauncher.java:118) - Job: [FlowJob: [name=firstJob]] launched
with the following parameters: [{currentTime=1353878959462}]
25.11.2012 21:29:19 DEBUG (AbstractJob.java:278) - Job execution starting: JobExecution: id=0, version=0,
startTime=null, endTime=null, lastUpdated=Sun Nov 25 21:29:19 GMT 2012, status=STARTING, exitStatus=exitCode=UNKNOWN;
exitDescription=, job=[JobInstance: id=0, version=0, JobParameters=[{currentTime=1353878959462}], Job=[firstJob]]
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:135) - Resuming state=firstJob.firstStep with status=UNKNOWN
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.firstStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [firstStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=1
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : First Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:209) - Step execution success: id=1
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=1, version=3,
name=firstStep, status=COMPLETED, exitStatus=COMPLETED,
readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.firstStep with status=COMPLETED25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.secondStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [secondStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=2
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Second Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:209) - Step execution success: id=2
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=2, version=3,
name=secondStep, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,
writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.secondStep with status=COMPLETED
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.thirdStep25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [thirdStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=3
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Third Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=3, version=3, name=thirdStep,
status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0,
processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.thirdStep with status=COMPLETED
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.end3
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.end3 with status=COMPLETED
25.11.2012 21:29:20 DEBUG (AbstractJob.java:294) - Job execution complete: JobExecution: id=0, version=1, startTime=Sun Nov 25 21:29:19 GMT 2012,
endTime=null, lastUpdated=Sun Nov 25 21:29:19 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=,
job=[JobInstance: id=0, version=0, JobParameters=[{currentTime=1353878959462}], Job=[firstJob]]
25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:121) - Job: [FlowJob: [name=firstJob]] completed with the following
parameters: [{currentTime=1353878959462}] and the following status: [COMPLETED]
25.11.2012 21:29:20 DEBUG (BatchProcessStarter.java:44) - JobExecution: id=0, version=2, startTime=Sun Nov 25 21:29:19 GMT 2012,
endTime=Sun Nov 25 21:29:20 GMT 2012, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=,
job=[JobInstance: id=0, version=0, JobParameters=[{currentTime=1353878959462}], Job=[firstJob]]

Second Job的控制台输出:

25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:118) - Job: [FlowJob: [name=secondJob]] launched with the following parameters: [{currentTime=1353878959462}]
25.11.2012 21:29:20 DEBUG (AbstractJob.java:278) - Job execution starting: JobExecution: id=1, version=0, startTime=null, endTime=null,
lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=1, version=0,
JobParameters=[{currentTime=1353878959462}], Job=[secondJob]]
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:135) - Resuming state=secondJob.fourthStep with status=UNKNOWN
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=secondJob.fourthStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [fourthStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=4
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Fourth Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=4, version=3, name=fourthStep, status=COMPLETED,
exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=secondJob.fourthStep with status=COMPLETED25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=secondJob.fifthStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [fifthStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=5
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Fifth Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=5, version=3, name=fifthStep, status=COMPLETED,
exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=secondJob.fifthStep with status=COMPLETED
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=secondJob.end5
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=secondJob.end5 with status=COMPLETED
25.11.2012 21:29:20 DEBUG (AbstractJob.java:294) - Job execution complete: JobExecution: id=1, version=1, startTime=Sun Nov 25 21:29:20 GMT 2012,
endTime=null, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=1,
version=0, JobParameters=[{currentTime=1353878959462}], Job=[secondJob]]
25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:121) - Job: [FlowJob: [name=secondJob]] completed with
the following parameters: [{currentTime=1353878959462}] and the following status: [COMPLETED]
25.11.2012 21:29:20 DEBUG (BatchProcessStarter.java:48) - JobExecution: id=1, version=2, startTime=Sun Nov 25 21:29:20 GMT 2012,
endTime=Sun Nov 25 21:29:20 GMT 2012, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=,
job=[JobInstance: id=1, version=0, JobParameters=[{currentTime=1353878959462}], Job=[secondJob]]

Third Job的控制台输出:

25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:118) - Job: [FlowJob: [name=thirdJob]] launched with the following parameters: [{currentTime=1353878959462}]
25.11.2012 21:29:20 DEBUG (AbstractJob.java:278) - Job execution starting: JobExecution: id=2, version=0, startTime=null, endTime=null,
lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=2, version=0,
JobParameters=[{currentTime=1353878959462}], Job=[thirdJob]]
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:135) - Resuming state=thirdJob.sixthStep with status=UNKNOWN
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=thirdJob.sixthStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [sixthStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=6
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Sixth Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=6, version=3, name=sixthStep, status=COMPLETED,
exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=thirdJob.sixthStep with status=COMPLETED25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=thirdJob.seventhStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [seventhStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=7
25.11.2012 21:29:20 DEBUG (FailedStepTasklet.java:33) - Task Result : Error occurred!
25.11.2012 21:29:20 DEBUG (TaskletStep.java:456) - Rollback for Exception: java.lang.Exception: Error occurred!
25.11.2012 21:29:20 DEBUG (TransactionTemplate.java:152) - Initiating transaction rollback on application exception...25.11.2012 21:29:20 DEBUG (AbstractPlatformTransactionManager.java:821) - Initiating transaction rollback
25.11.2012 21:29:20 DEBUG (ResourcelessTransactionManager.java:54) - Rolling back resourceless transaction
on [org.springframework.batch.support.transaction.ResourcelessTransactionManager
$ResourcelessTransaction@40874c04]
25.11.2012 21:29:20 DEBUG (RepeatTemplate.java:291) - Handling exception: java.lang.Exception, caused by: java.lang.Exception: Error occurred!
25.11.2012 21:29:20 DEBUG (RepeatTemplate.java:251) - Handling fatal exception explicitly (rethrowing first of 1): java.lang.Exception: Error occurred!
25.11.2012 21:29:20 ERROR (AbstractStep.java:222) - Encountered an error executing the step...25.11.2012 21:29:20 DEBUG (ResourcelessTransactionManager.java:34) - Committing resourceless transaction on
[org.springframework.batch.support.transaction.ResourcelessTransactionManager
$ResourcelessTransaction@66a7d863]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=7, version=2,
name=seventhStep, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,
writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1
25.11.2012 21:29:20 DEBUG (ResourcelessTransactionManager.java:34) - Committing resourceless transaction on
[org.springframework.batch.support.transaction.ResourcelessTransactionManager
$ResourcelessTransaction@156f803c]
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=thirdJob.seventhStep with status=FAILED
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=thirdJob.fail8
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=thirdJob.fail8 with status=FAILED
25.11.2012 21:29:20 DEBUG (AbstractJob.java:294) - Job execution complete: JobExecution: id=2, version=1,
startTime=Sun Nov 25 21:29:20 GMT 2012, endTime=null, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=FAILED,
exitStatus=exitCode=FAILED;exitDescription=, job=[JobInstance: id=2, version=0, JobParameters=[{currentTime=1353878959462}], Job=[thirdJob]]
25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:121) - Job: [FlowJob: [name=thirdJob]] completed with
the following parameters: [{currentTime=1353878959462}] and the following status: [FAILED]
25.11.2012 21:29:20 DEBUG (BatchProcessStarter.java:52) - JobExecution: id=2, version=2, startTime=Sun Nov 25 21:29:20 GMT 2012,
endTime=Sun Nov 25 21:29:20 GMT 2012, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=FAILED, exitStatus=exitCode=FAILED;
exitDescription=, job=[JobInstance: id=2, version=0, JobParameters=[{currentTime=1353878959462}], Job=[thirdJob]]

重新启动后,First Job的控制台输出:

25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:118) - Job: [FlowJob: [name=firstJob]] launched with the following parameters: [{currentTime=1353878960660}]
25.11.2012 21:29:20 DEBUG (AbstractJob.java:278) - Job execution starting: JobExecution: id=3, version=0, startTime=null,
endTime=null, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=,
job=[JobInstance: id=3, version=0, JobParameters=[{currentTime=1353878960660}], Job=[firstJob]]
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:135) - Resuming state=firstJob.firstStep with status=UNKNOWN
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.firstStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [firstStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=8
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : First Task is executed...
25.11.2012 21:29:20 DEBUG (AbstractStep.java:209) - Step execution success: id=8
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=8, version=3, name=firstStep,
status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.firstStep with status=COMPLETED25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.secondStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [secondStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=9
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Second Task is executed...
25.11.2012 21:29:20 DEBUG (TaskletStep.java:417) - Applying contribution: [StepContribution: read=0, written=0, filtered=0,
readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:209) - Step execution success: id=9
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=9, version=3, name=secondStep,
status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.secondStep with status=COMPLETED25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.thirdStep
25.11.2012 21:29:20  INFO (SimpleStepHandler.java:133) - Executing step: [thirdStep]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:180) - Executing: id=10
25.11.2012 21:29:20 DEBUG (SuccessfulStepTasklet.java:33) - Task Result : Third Task is executed...
25.11.2012 21:29:20 DEBUG (TaskletStep.java:417) - Applying contribution: [StepContribution: read=0, written=0, filtered=0,
readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
25.11.2012 21:29:20 DEBUG (AbstractStep.java:209) - Step execution success: id=10
25.11.2012 21:29:20 DEBUG (AbstractStep.java:273) - Step execution complete: StepExecution: id=10, version=3, name=thirdStep,
status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.thirdStep with status=COMPLETED
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:143) - Handling state=firstJob.end3
25.11.2012 21:29:20 DEBUG (SimpleFlow.java:156) - Completed state=firstJob.end3 with status=COMPLETED
25.11.2012 21:29:20 DEBUG (AbstractJob.java:294) - Job execution complete: JobExecution: id=3, version=1, startTime=Sun Nov 25 21:29:20 GMT 2012,
endTime=null, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=3,
version=0, JobParameters=[{currentTime=1353878960660}], Job=[firstJob]]
25.11.2012 21:29:20  INFO (SimpleJobLauncher.java:121) - Job: [FlowJob: [name=firstJob]] completed with
the following parameters: [{currentTime=1353878960660}] and the following status: [COMPLETED]
25.11.2012 21:29:20 DEBUG (BatchProcessStarter.java:57) - JobExecution: id=3, version=2, startTime=Sun Nov 25 21:29:20 GMT 2012,
endTime=Sun Nov 25 21:29:20 GMT 2012, lastUpdated=Sun Nov 25 21:29:20 GMT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=,
job=[JobInstance: id=3, version=0, JobParameters=[{currentTime=1353878960660}], Job=[firstJob]]

步骤11:下载

https://github.com/erenavsarogullari/OTV_SpringBatch_TaskletStep

相关链接 :

Spring Batch –参考文档
Spring Batch – API文档

参考: Online Technology Vision博客上的JCG合作伙伴 Eren Avsarogullari提供的Spring Batch中面向TaskletStep的处理 。

翻译自: https://www.javacodegeeks.com/2012/12/taskletstep-oriented-processing-in-spring-batch.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/370475.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

布局中常见的居中问题

说到布局除了浮动以及定位外还有一个不得不提的点&#xff0c;那就是居中&#xff0c;居中问题我们在网页布局当中经常遇到&#xff0c;那么以下就是分为两部分来讲&#xff0c;一部分是传统的居中&#xff0c;另一种则是flex居中&#xff0c;每个部分又通过分为水平垂直居中来…

排序算法——桶排序

把数据放进若干个桶&#xff0c;然后在桶里用其他排序&#xff0c;近乎分治思想。从数值的低位到高位依次排序&#xff0c;有几位就排序几次。例如二位数就排两次&#xff0c;三位数就排三次&#xff0c;依次按照个十百...的顺序来排序。 第一次排序&#xff1a;50 12 …

原型设计模式:创建另一个小车

创建对象确实是一个耗时的过程&#xff0c;也是一件昂贵的事情。 因此&#xff0c;我们现在正努力节省时间和金钱。 我们该怎么做&#xff1f; 克隆奇迹多莉 有人记得多莉吗&#xff1f; 是的&#xff0c;是绵羊&#xff0c;是第一个被克隆的哺乳动物。 好吧&#xff0c;我不想…

java实现周期任务_java定时任务的实现方式

本文列举常见的java定时任务实现方式&#xff0c;并做一定比较。1. 循环内部sleep实现周期执行创建一个thread&#xff0c;run() while循环里sleep()来实现周期性执行; 简单粗暴&#xff0c;作为一个初学者很容易想到。public class Task1 {public static void main(String[] a…

HTTPS协议在Tomcat中启用的配置

本文将讲解HTTPS协议在Tomcat中启用是如何配置的。 概念简介 Tomcat 服务器是一个免费的开放源代码的Web 应用服务器&#xff0c;属于轻量级应用服务器&#xff0c;在中小型系统和并发访问用户不是很多的场合下被普遍使用&#xff0c;是开发和调试 JSP 程序的首选。 HTTP 超文本…

CSS3实现烟花特效 --web前端

烟花特效&#xff0c;比较简单&#xff0c;直接贴代码了……<!DOCTYPE html><html lang"en"><head> <meta charset"UTF-8"> <title>css3实现烟花特效</title> <style> * { margin: 0; padding: 0; } html{ widt…

java.lang.ClassNotFoundException:如何解决

本文适用于当前面临java.lang.ClassNotFoundException挑战的Java初学者。 它将为您提供此常见Java异常的概述&#xff0c;这是一个示例Java程序&#xff0c;可支持您的学习过程和解决策略。 如果您对与更高级的类加载器相关的问题感兴趣&#xff0c;我建议您复习有关java.lang…

小程序实践(三):九宫格实现及item跳转

效果图&#xff1a; 实现效果图红色线包含部分的九宫格效果&#xff0c;并附带item点击时间。 ------------------------------------------------------------------------------------------------------ 具体实现&#xff1a; 1、首先添加图片资源文件 在项目根目录新建一个…

用JavaFX编写图块引擎

随着JavaFX嵌入式版本的问世&#xff0c;我们的框架对于游戏开发变得越来越有趣&#xff0c;因为我们现在可以瞄准平板电脑和智能手机等小型消费类设备。 因此&#xff0c;我决定对JavaFX进行更多的游戏编写实验。 这次&#xff0c;我想使用Canvas对渲染进行更多控制&#xff0…

HTML5--应用网页模板

因为刚开始写博客,只想着把知识点记录在这,也想给你们一些参考,在布局上有些没有思考太多;回过头来看,实在是不忍直视,对不住之前阅读的100 ,既然昨天的事无法挽回,那就从现在开始从新整改吧!也希望大家看了,能对你们有所帮助 1.先给大家看看效果图,好让大家有点兴趣 2.大家再来…

企业集成模式简介

在此博客文章中&#xff0c;我们将介绍一些企业集成模式。 这些是旨在解决集成挑战的已知设计模式。 阅读此书后&#xff0c;您将可以设计集成解决方案。 EIP&#xff08;简而言之&#xff09;是已知的设计模式&#xff0c;可为应用程序集成过程中遇到的问题/问题提供解决方案…

手把手教你Chrome浏览器安装Postman(含下载云盘链接)【转载】

转载自&#xff1a;http://www.ljwit.com/archives/php/278.html 说明&#xff1a; Postman不多介绍&#xff0c;是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件。本文主要介绍下安装过程。 本文使用的是解压文件直接进行安装。是比较快速有效的安装方式&#xff0c;…

C语言博客作业--数据类型

题目1&#xff1a;7-4 打印菱形图案 1. 本题PTA提交列表 2. 设计思路 1.定义变量i,j,k,n;且声明i为要打印的行数&#xff0c;j是控制输出打印空格和星星&#xff0c;n是菱形为菱形的高 2.输入n 3.i1&#xff0c;j1 4.先打印上半部分&#xff0c;第一行到n/21行&#xff0c;输出…

信息隐藏将txt文件合并到jpg文件中_使用Kali Linux在图像内隐藏机密消息—可在任何Linux发行版使用

欢迎回到“Esn技术社区”&#xff01;今天&#xff0c;我们将演示如何使用Steghide(一种可在Kali Linux上使用的流行隐写工具)在图像内隐藏消息。在计算机科学中&#xff0c;将信息隐藏在文件内(例如图像&#xff0c;文档&#xff0c;程序&#xff0c;有用数据&#xff0c;消息…

java方法调用机制_Java方法调用机制 - osc_bkdv2it5的个人空间 - OSCHINA - 中文开源技术交流社区...

最近在编程时&#xff0c;修改方法传入对象的对象引用&#xff0c;并没有将修改反映到调用方法中。奇怪为什么结果没有变化&#xff0c;原因是遗忘了Java对象引用和内存分配机制。本文介绍3个点&#xff1a;① 该问题举例说明② 简要阐述Java内存区域③ 介绍JVM中方法调用的机制…

CSS染色图标(图片)

之前一直以为用background引入的图标无法染色&#xff08;非字体图标&#xff09;&#xff0c;现在才知道有黑科技可以用&#xff0c;就是利用drop-shadow。 代码示例 <!DOCTYPE html> <html> <head lang"en"><meta charset"UTF-8"&…

eclipse安装java web插件

1 查看eclipse版本 找到eclipse的安装目录&#xff0c;找到readme文件&#xff0c;打开其中的html文件&#xff0c;我的是4.6版本的,代号是oxygen 2 安装 打开eclipse,点击help-Install new software-单击add&#xff0c;在弹出窗口中输入网址&#xff1a; http://download.ecl…

实现输入框小数多 自动进位展示,编辑时实际值不变

今天遇到个业务需求&#xff0c;要求输入框&#xff0c;输入数字的小数位数可以很多位&#xff0c;但移开后显示&#xff0c;只显示小数点后两位 &#xff08;四舍五入&#xff09;&#xff0c;当要编辑的时候&#xff0c;展现其原来的输入数据。 闲话不多说&#xff0c;当时也…

使用Jasper Reports以Java创建报告

上周&#xff0c;我试图使用Jasper创建报告。 在这篇文章中&#xff0c;我将记录一些资源和链接&#xff0c;以便对任何寻求类似信息的人都有用。 我将介绍Jasper报告&#xff0c;示例和Dynamic Jasper的生命周期。 Jasper Reports是世界上最受欢迎的开源报告引擎。 它完全用…

CentOS7 安装NodeJS

一、切换目录到/usr/local/src 命令行&#xff1a;cd /usr/local/src 二、下载node.js&#xff08;我这里下载的是二进制的源码&#xff09; 命令行&#xff1a; wget https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xz 图片&#xff1a; 三、解压压缩包 命令行&am…