[JAVA] Create a simple batch processing framework in Eclipse.

This article is a direct description of what I did when creating a batch process in Eclipse, first trying to create a simple framework.

The image of batch processing itself is that processing time is long (inputting a large amount of data, processing, and outputting) as a separate process. So, I didn't have the idea of jobs or tasks, and I imagined something like executing a long process in the main function. However, when actually using the functions of Spring Framework, it was necessary to think about jobs and tasks. So, first, execute the job from the main function, execute the task from the job, and make up to the point where the exit code is set.

First, let's create the following batch process. ・ BatchTestApplication (main) => Start BatchTestJob. (Using Spring Framework) ・ BatchTetJob => Start BatchTestTasklet. ・ BatchTestTasklet => Output "BatchTestTasklet Start OK" (set the exit code to 1)

Point: Setting the exit code in batch processing is a bit complicated. (1) Implement the ExitCodeGenerator interface in the BatchTestTasklet class. (2) Override the getExitCode method and return the return value in it. (3) The return value of (2) is set in the return value of SpringApplication.exit.


package com.example.demo;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext;

@SpringBootApplication public class BatchTestAppApplication {

public static void main(String[] args) {
	ApplicationContext context = SpringApplication.run(BatchTestAppApplication.class, args);
	int iRet = SpringApplication.exit(context);



package com.example.demo;

import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component;

@Component @EnableBatchProcessing public class BatchTestJob {

private JobBuilderFactory jobFactory;

private StepBuilderFactory stepFactory;

private BatchTestTasklet batchTestTasklet;

public Step step1() {
	return stepFactory

public Job job(Step step1) {

	return jobFactory
			.incrementer(new RunIdIncrementer())



package com.example.demo;

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; import org.springframework.boot.ExitCodeGenerator; import org.springframework.stereotype.Component;

@Component public class BatchTestTasklet implements Tasklet, ExitCodeGenerator {

public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

	System.out.println("BatchTestTasklet Start OK");
	return RepeatStatus.FINISHED;

public int getExitCode() {
	return 1;


Recommended Posts

Create a simple batch processing framework in Eclipse.
Create a base for your batch processing project in Eclipse.
Create a Servlet program in Eclipse
Create a simple on-demand batch with Spring Batch
Let's create a super-simple web framework in Java
Create a tomcat project using Eclipse Pleiades All in One
3 Implement a simple interpreter in Java
Create a tomcat project using Eclipse
Create a database in a production environment
Create a new app in Rails
Create a Java project using Eclipse
A simple sample callback in Java
I tried to create a simple map app in Android Studio
Create a simple web application with Dropwizard
Building a Lambda development environment in Eclipse
[Rails withdrawal] Create a simple withdrawal function with rails
Create a simple bar chart with MPAndroidChart
Play Framework 2.6 (Java) environment construction in Eclipse
Create a TODO app in Java 7 Create Header
[Rails] Let's create a super simple Rails API
Escape processing when creating a URL in Ruby
Create a simple search app with Spring Boot
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
Try to create a bulletin board in Java
Let's create a custom tab view in SwiftUI 2.0
How to create a theme in Liferay 7 / DXP
Draw a too beloved Mandelbrot set in Processing
Create a tool for name identification in Salesforce
[1st] How to create a Spring-MVC framework project
How to easily create a pull-down in Rails
Create a native extension of Ruby in Rust
How to automatically generate a constructor in Eclipse
MVC in Eclipse.
Create versatile processing
I made a simple calculation problem game in Java
Submit a job to AWS Batch with Java (Eclipse)
[CentOS, Eclipse] Load a library file in a C project
How to create a Spring Boot project in IntelliJ
I tried to create a Clova skill in Java
[Personal memo] Make a simple deep copy in Java
How to create a data URI (base64) in Java
Addition of variables in iterative processing in a while statement
Create a simple demo site with Spring Security with Spring Boot 2.1
[Programming complete] §5 Create a review management app in Ruby
Call a program written in Swift from Processing (Java)
Create a frameless non-rectangular window in JavaFX without a taskbar