Job
interface is provided by Spring Batch in the form of the SimpleJob
class which creates some standard functionality on top of Job
, however the batch namespace abstracts away the need to instantiate it directly. Instead, the <job>
tag can be used:<job id="myEmpExpireJob"> <!-- Step bean details ommitted for clarity --> <step id="readEmployeeData" next="writeEmployeeData"></step> <step id="writeEmployeeData" next="employeeDataProcess"></step> <step id="employeeDataProcess"></step> </job>JobInstance-
JobInstance
refers to the concept of a logical job run. Let's consider a batch job that should be run once at the end of the day, such as the 'EndOfDay' job from the diagram above. There is one 'EndOfDay' Job
, but each individual run of the Job
must be tracked separately. In the case of this job, there will be one logical JobInstance
per day. For example, there will be a January 1st run, and a January 2nd run. If the January 1st run fails the first time and is run again the next day, it is still the January 1st run.Job
defines what a job is and how it is to be executed, and JobInstance
is a purely organizational object to group executions together, primarily to enable correct restart semantics. A JobExecution
, however, is the primary storage mechanism for what actually happened during a run, and as such contains many more properties that must be controlled and persisted: status | A BatchStatus object that indicates the status of the execution. While running, it's BatchStatus.STARTED, if it fails, it's BatchStatus.FAILED, and if it finishes successfully, it's BatchStatus.COMPLETED |
startTime | A java.util.Date representing the current system time when the execution was started. |
endTime | A java.util.Date representing the current system time when the execution finished, regardless of whether or not it was successful. |
exitStatus | The ExitStatus indicating the result of the run. It is most important because it contains an exit code that will be returned to the caller. See chapter 5 for more details. |
createTime | A java.util.Date representing the current system time when the JobExecution was first persisted. The job may not have been started yet (and thus has no start time), but it will always have a createTime, which is required by the framework for managing job level ExecutionContext s. |
lastUpdated | A java.util.Date representing the last time a JobExecution was persisted. |
executionContext | The 'property bag' containing any user data that needs to be persisted between executions. |
failureExceptions | The list of exceptions encountered during the execution of a Job . These can be useful if more than one exception is encountered during the failure of a Job . |
status | A BatchStatus object that indicates the status of the execution. While it's running, the status is BatchStatus.STARTED, if it fails, the status is BatchStatus.FAILED, and if it finishes successfully, the status is BatchStatus.COMPLETED |
startTime | A java.util.Date representing the current system time when the execution was started. |
endTime | A java.util.Date representing the current system time when the execution finished, regardless of whether or not it was successful. |
exitStatus | The ExitStatus indicating the result of the execution. It is most important because it contains an exit code that will be returned to the caller. See chapter 5 for more details. |
executionContext | The 'property bag' containing any user data that needs to be persisted between executions. |
readCount | The number of items that have been successfully read |
writeCount | The number of items that have been successfully written |
commitCount | The number transactions that have been committed for this execution |
rollbackCount | The number of times the business transaction controlled by the Step has been rolled back. |
readSkipCount | The number of times read has failed, resulting in a skipped item. |
processSkipCount | The number of times process has failed, resulting in a skipped item. |
filterCount | The number of items that have been 'filtered' by the ItemProcessor . |
writeSkipCount | The number of times write has failed, resulting in a skipped item. |
<job-repository id="jobRepository"/>
public interface JobLauncher { public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException; }Item Reader-
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/batch" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd"> <job id="ioSampleJob"> <step id="step1"> <tasklet> <chunk commit-interval="2" reader="itemReader" writer="itemWriter"></chunk> </tasklet> </step> </job> </beans:beans>
Labels: Spring Batch