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.pswp.cn/news/370475.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/370475.shtml
英文地址,請注明出處:http://en.pswp.cn/news/370475.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

布局中常見的居中問題

說到布局除了浮動以及定位外還有一個不得不提的點&#xff0c;那就是居中&#xff0c;居中問題我們在網頁布局當中經常遇到&#xff0c;那么以下就是分為兩部分來講&#xff0c;一部分是傳統的居中&#xff0c;另一種則是flex居中&#xff0c;每個部分又通過分為水平垂直居中來…

unity json解析IPA后續

以前說到的&#xff0c;有很大的限制&#xff0c;只能解析簡單的類&#xff0c;如果復雜的就會有問題&#xff0c;從老外哪里看到一片博客&#xff0c;是將類中的list 等復雜對象序列化&#xff0c; using UnityEngine; using System.Collections; using System.Collections.…

改善代碼質量之內連臨時變量

待增轉載于:https://www.cnblogs.com/muyl/articles/6940896.html

python 矩陣元素相加_Numpy中元素級運算

標量與矩陣的運算:加法&#xff1a;values [1,2,3,4,5]values np.array(values) 5#現在 values 是包含 [6,7,8,9,10] 的一個 ndarray乘法&#xff1a;x np.multiply(some_array, 5)x some_array * 5矩陣與矩陣的運算:加法&#xff1a;對應元素相加&#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…

磁盤鏡像工具Guymager

磁盤鏡像工具Guymager在數字取證中&#xff0c;經常需要對磁盤制作鏡像&#xff0c;以便于后期分析。Kali Linux提供一款輕量級的磁盤鏡像工具Guymager。該工具采用圖形界面化方式&#xff0c;提供磁盤鏡像和磁盤克隆功能。它不僅生成dd的鏡像&#xff0c;還能生成EWF和AFF鏡像…

python怎么寫代碼求年華收益率_如何計算年化收益率?

關于投資年化收益率的計算&#xff0c;三思君覺得主要有三種&#xff0c;分別是一次性投資的收益率計算、定期定額的收益率計算、不定期不定額的收益率計算。1.一次性投資的收益率計算對于一次性投資的收益率&#xff0c;相信大家都會計算。比如&#xff0c;小李同學去年買了一…

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 開發_深入淺出 Java 虛擬機 · 通往高級 Java 開發的必經之路

第一章 JVM 內存模型Java 虛擬機(Java Virtual MachineJVM)的內存空間分為五個部分&#xff0c;分別是&#xff1a;程序計數器Java 虛擬機棧本地方法棧堆方法區。下面對這五個區域展開深入的介紹。1.1 程序計數器1.1.1 什么是程序計數器&#xff1f;程序計數器是一塊較小的內存…

java.lang.ClassNotFoundException:如何解決

本文適用于當前面臨java.lang.ClassNotFoundException挑戰的Java初學者。 它將為您提供此常見Java異常的概述&#xff0c;這是一個示例Java程序&#xff0c;可支持您的學習過程和解決策略。 如果您對與更高級的類加載器相關的問題感興趣&#xff0c;我建議您復習有關java.lang…

iOS10 App跳轉到系統設置

實現類似萬能鑰匙中點擊一個Wi-Fi跳轉到系統Wi-Fi設置界面的功能。 NSString * urlString "App-Prefs:rootWIFI";if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {if ([[UIDevice currentDevice].systemVersion doubleValue…

python生成器 圖片分類_python批量處理圖片圖片Python迭代器和生成器介紹

Python迭代器和生成器介紹迭代器迭代器是一個實現了迭代器協議的對象&#xff0c;Python中的迭代器協議就是有next方法的對象會前進到下一結果&#xff0c;而在一系列結果的末尾是&#xff0c;則會引發StopIteration。在for循環中&#xff0c;Python將自動調用工廠函數iter()獲…

Java-IO流之BufferedReader 和BufferedWriter的使用和原理

BufferedReader和BufferedWriter出現的目的是為了對FileReader以及FileWriter的讀寫操作進行增強&#xff0c;而怎么增強呢&#xff0c;原理類似于使用StringBuilder&#xff0c;是把數據先放入他們的一個char數組中&#xff0c;然后再操作char數組。 使用緩沖區的字符流是使用…

小程序實踐(三):九宮格實現及item跳轉

效果圖&#xff1a; 實現效果圖紅色線包含部分的九宮格效果&#xff0c;并附帶item點擊時間。 ------------------------------------------------------------------------------------------------------ 具體實現&#xff1a; 1、首先添加圖片資源文件 在項目根目錄新建一個…

用JavaFX編寫圖塊引擎

隨著JavaFX嵌入式版本的問世&#xff0c;我們的框架對于游戲開發變得越來越有趣&#xff0c;因為我們現在可以瞄準平板電腦和智能手機等小型消費類設備。 因此&#xff0c;我決定對JavaFX進行更多的游戲編寫實驗。 這次&#xff0c;我想使用Canvas對渲染進行更多控制&#xff0…

python命令行運行模式_[Python] 命令行模式閱讀博客園的博文

1 #-*- coding:UTF-8 -*-2 importrequests3 from lxml importetree4 importsys5 importio6 importos789 sys.stdout io.TextIOWrapper(sys.stdout.buffer, encodinggb18030)101112 classCnBlogs:13 """"14 Auth&#xff1a;reader15 發表地址&#xff1a;…

HTML5--應用網頁模板

因為剛開始寫博客,只想著把知識點記錄在這,也想給你們一些參考,在布局上有些沒有思考太多;回過頭來看,實在是不忍直視,對不住之前閱讀的100 ,既然昨天的事無法挽回,那就從現在開始從新整改吧!也希望大家看了,能對你們有所幫助 1.先給大家看看效果圖,好讓大家有點興趣 2.大家再來…