This tutorial, spring batch quartz scheduler, will show you how to schedule the task repeatedly for reading a CSV file data and writing to XML file after some modification to the input CSV file using Quartz Scheduler API.

In my previous tutorial I have shown how to do the same thing using spring’s built-in TaskScheduler API.

You can read the tutorial Spring Batch to read what is Spring Batch and what are the usages of Spring Batch.

Related Posts:

Prerequisites

Eclipse, Java 8, Gradle 4.10.2, Spring Boot 2.1.4, Spring Batch

Example with Source Code

We’ll build a service that imports data from a CSV file, transforms it with custom code, and store the final results in xml file. And schedule the same task repeatedly using spring batch quartz scheduler API.

Creating Project

Create Gradle based project in Eclipse. You can give the project name as spring-batch-quartz-scheduler.

Updating Build Script

Make sure to have the following build.gradle script.

buildscript {
	ext {
		springBootVersion = '2.1.4.RELEASE'
	}
    repositories {
    	mavenLocal()
    	mavenCentral()
    }
    dependencies {
    	classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
	mavenLocal()
    mavenCentral()
}
dependencies {
	compile("org.springframework.boot:spring-boot-starter-batch:${springBootVersion}")
	compile('org.springframework:spring-context-support:5.1.7.RELEASE')
	compile("org.springframework:spring-oxm:5.1.7.RELEASE")
	compile('org.quartz-scheduler:quartz:2.3.1')
	compile('mysql:mysql-connector-java:5.1.13')
}

We have added required dependencies, such as, Quartz API, MySQL database connector, JAXB API etc.

We need to add spring-context-support dependency for working with Quartz API.

Creating VO Class

Create a model class Person.java which will represent a row of data for inputs and outputs.

I have made the below class JAXB annotation enabled for converting Java object to XML directly without writing our own code for converting.

package com.roytuts.spring.batch.vo;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "person")
public class Person {
	private int id;
	private String firstName;
	private String lastName;
	@XmlAttribute(name = "id")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@XmlElement(name = "firstName")
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	@XmlElement(name = "lastName")
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	@Override
	public String toString() {
		return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]";
	}
}

Creating Mapper Class

Create below mapper class which will map the CSV file row item to Java object.

Each row in CSV file has first field as integer value, second field as string value and third field as string value.

package com.roytuts.spring.batch.fieldset.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import com.roytuts.spring.batch.vo.Person;
public class PersonFieldSetMapper implements FieldSetMapper<Person> {
	@Override
	public Person mapFieldSet(FieldSet fieldSet) {
		Person person = new Person();
		person.setId(fieldSet.readInt(0));
		person.setFirstName(fieldSet.readString(1));
		person.setLastName(fieldSet.readString(2));
		return person;
	}
}

Creating Processor Class

Create an intermediate processor.

A common paradigm in batch processing is to ingest data, transform it, and then pipe it out somewhere else.

Here we write a simple transformer that converts the initial characters of the names to uppercase. You can write other processing logic according to your project requirements.

package com.roytuts.spring.batch.itemprocessor;
import org.springframework.batch.item.ItemProcessor;
import com.roytuts.spring.batch.vo.Person;
public class PersonItemProcessor implements ItemProcessor<Person, Person> {
	@Override
	public Person process(Person person) throws Exception {
		System.out.println("Processing: " + person);
		final String initCapFirstName = person.getFirstName().substring(0, 1).toUpperCase()
				+ person.getFirstName().substring(1);
		final String initCapLastName = person.getLastName().substring(0, 1).toUpperCase()
				+ person.getLastName().substring(1);
		Person transformedPerson = new Person();
		transformedPerson.setId(person.getId());
		transformedPerson.setFirstName(initCapFirstName);
		transformedPerson.setLastName(initCapLastName);
		return transformedPerson;
	}
}

Creating CSV File

Create below CSV file under src/main/resources directory.

This is a very simple file that contains each row with id, first name and last name.

1000,soumitra,roy
1001,souvik,sanyal
1002,arup,chatterjee
1003,suman,mukherjee
1004,debina,guha
1005,liton,sarkar
1006,debabrata,poddar

Creating Scheduler Class

Create below scheduler class in spring batch quartz scheduler example, which extends QuartzJobBean, which acts as a bridge between Quartz and Spring Batch.

package com.roytuts.spring.batch.quartz.scheduler;
import java.util.Map;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class SpringBatchQuartzScheduler extends QuartzJobBean {
	private JobLocator jobLocator;
	private JobLauncher jobLauncher;
	public void setJobLocator(JobLocator jobLocator) {
		this.jobLocator = jobLocator;
	}
	public void setJobLauncher(JobLauncher jobLauncher) {
		this.jobLauncher = jobLauncher;
	}
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		Map<String, Object> jobMap = context.getMergedJobDataMap();
		String jobName = (String) jobMap.get("jobName");
		try {
			JobExecution execution = jobLauncher.run(jobLocator.getJob(jobName),
					new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis()).toJobParameters());
			System.out.println("Job Status : " + execution.getStatus());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		System.out.println("Done");
	}
}

Creating Configuration Class

We have created this Spring Configuration class to define several beans for Spring Batch processing.

We have defined beans, such as, ItemProcessor, TransactionManager, JobRepository, DataSource, JobLauncher, Step, Job etc. for our Spring Batch processing.

We used Jaxb2Marshaller to marshall Java POJO to XML.

We write the final output into an XML file (person<today’s date>.xml) under C:/workspace directory.

package com.roytuts.spring.batch.config;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.JobRegistry;
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.configuration.support.JobRegistryBeanPostProcessor;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.item.xml.StaxEventItemWriter;
import org.springframework.batch.support.DatabaseType;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import com.roytuts.spring.batch.itemprocessor.PersonItemProcessor;
import com.roytuts.spring.batch.quartz.scheduler.SpringBatchQuartzScheduler;
import com.roytuts.spring.batch.vo.Person;
@Configuration
@EnableBatchProcessing
public class SpringBatchConfig {
	@Bean
	@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
	public Person person() {
		return new Person();
	}
	@Bean
	@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
	public ItemProcessor<Person, Person> itemProcessor() {
		return new PersonItemProcessor();
	}
	@Bean
	public DataSource dataSource() {
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName("com.mysql.jdbc.Driver");
		dataSource.setUrl("jdbc:mysql://localhost:3306/roytuts");
		dataSource.setUsername("root");
		dataSource.setPassword("");
		ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
		databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-mysql.sql"));
		databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-mysql.sql"));
		DatabasePopulatorUtils.execute(databasePopulator, dataSource);
		return dataSource;
	}
	@Bean
	public ResourcelessTransactionManager txManager() {
		return new ResourcelessTransactionManager();
	}
	@Bean
	public JobRepository jbRepository(DataSource dataSource, ResourcelessTransactionManager transactionManager)
			throws Exception {
		JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
		factory.setDatabaseType(DatabaseType.MYSQL.getProductName());
		factory.setDataSource(dataSource);
		factory.setTransactionManager(transactionManager);
		return factory.getObject();
	}
	@Bean
	public JobLauncher jbLauncher(JobRepository jbRepository) {
		SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
		jobLauncher.setJobRepository(jbRepository);
		return jobLauncher;
	}
	@Bean
	public BeanWrapperFieldSetMapper<Person> beanWrapperFieldSetMapper() {
		BeanWrapperFieldSetMapper<Person> fieldSetMapper = new BeanWrapperFieldSetMapper<>();
		fieldSetMapper.setPrototypeBeanName("person");
		return fieldSetMapper;
	}
	@Bean
	public FlatFileItemReader<Person> fileItemReader(BeanWrapperFieldSetMapper<Person> beanWrapperFieldSetMapper) {
		FlatFileItemReader<Person> fileItemReader = new FlatFileItemReader<>();
		fileItemReader.setResource(new ClassPathResource("person.csv"));
		DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
		delimitedLineTokenizer.setNames("id", "firstName", "lastName");
		DefaultLineMapper<Person> defaultLineMapper = new DefaultLineMapper<>();
		defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
		defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
		fileItemReader.setLineMapper(defaultLineMapper);
		return fileItemReader;
	}
	@Bean(destroyMethod = "")
	public StaxEventItemWriter<Person> staxEventItemWriter(Jaxb2Marshaller marshaller) {
		StaxEventItemWriter<Person> staxEventItemWriter = new StaxEventItemWriter<>();
		staxEventItemWriter.setResource(new FileSystemResource("C:/workspace/person" + LocalDate.now() + ".xml"));
		staxEventItemWriter.setMarshaller(marshaller);
		staxEventItemWriter.setRootTagName("personInfo");
		return staxEventItemWriter;
	}
	@Bean
	public Job jobCsvXml(JobBuilderFactory jobBuilderFactory, Step step) {
		return jobBuilderFactory.get("jobCsvXml").incrementer(new RunIdIncrementer()).flow(step).end().build();
	}
	@Bean
	public Step step1(StepBuilderFactory stepBuilderFactory, ResourcelessTransactionManager transactionManager,
			ItemReader<Person> reader, ItemWriter<Person> writer, ItemProcessor<Person, Person> processor) {
		return stepBuilderFactory.get("step1").transactionManager(transactionManager).<Person, Person>chunk(2)
				.reader(reader).processor(processor).writer(writer).build();
	}
	@Bean
	public Jaxb2Marshaller jaxb2Marshaller() {
		Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
		jaxb2Marshaller.setClassesToBeBound(Person.class);
		return jaxb2Marshaller;
	}
	@Bean
	public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
		JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor=new JobRegistryBeanPostProcessor();
		jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
		return jobRegistryBeanPostProcessor;
	}
	@Bean
	public JobDetailFactoryBean jobDetailFactoryBean(Job jobCsvXml, JobLauncher jobLauncher, JobRegistry jobLocator) {
		JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
		jobDetailFactoryBean.setJobClass(SpringBatchQuartzScheduler.class);
		Map<String, Object> map = new HashMap<>();
		map.put("jobName", jobCsvXml.getName());
		map.put("jobLauncher", jobLauncher);
		map.put("jobLocator", jobLocator);
		jobDetailFactoryBean.setJobDataAsMap(map);
		return jobDetailFactoryBean;
	}
	@Bean
	public CronTriggerFactoryBean cronTriggerFactoryBean(JobDetailFactoryBean jobDetail) {
		CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
		cronTriggerFactoryBean.setJobDetail(jobDetail.getObject());
		cronTriggerFactoryBean.setStartDelay(2000);
		cronTriggerFactoryBean.setCronExpression("*/2 * * * * ?");
		return cronTriggerFactoryBean;
	}
	@Bean
	public SchedulerFactoryBean schedulerFactoryBean(CronTriggerFactoryBean cronTrigger) {
		SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
		schedulerFactoryBean.setTriggers(cronTrigger.getObject());
		return schedulerFactoryBean;
	}
}

A default simple implementation of the 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.

Step is a domain object that encapsulates an independent, sequential phase of a batch job. Therefore, every Job is composed entirely of one or more steps. A Step contains all of the information necessary to define and control the actual batch processing.

ItemReader is an abstraction that represents the retrieval of input for a Step, one item at a time.

ItemWriter is an abstraction that represents the output of a Step, one batch or chunk of items at a time. Generally, an item writer has no knowledge of the input it will receive next, only the item that was passed in its current invocation.

ItemProcessor is an abstraction that represents the business processing of an item. While the  ItemReader reads one item, and the ItemWriter writes them, the ItemProcessor provides access to transform or apply other business processing. If, while processing the item, it is determined that the item is not valid, returning null indicates that the item should not be written out.

TransactionManager – it will be used to begin and commit transactions during processing.

Chunk – The number of items that will be processed before the transaction is committed.

JobRepository is the persistence mechanism. It provides CRUD operations for JobLauncherJob and Step implementations. When a Job is first launched, a JobExecution is obtained from the repository, and during the course of execution StepExecution and JobExecution implementations are persisted by passing them to the repository.

JonLauncher represents a simple interface for launching a Job with a given set of JobParameters.

SchedulerFactoryBean that schedules the job for execution at regular interval that is specified in CronTriggerFactoryBean and starts the job at 2 seconds delay as specified in CronTriggerFactoryBean.

The JobRegistryBeanPostProcessor bean registers Job beans with JobRegistry, so that QuartzJobBean is able to get the Job bean via JobLocator(JobRegister).

Creating Main Class

Create below class for launching spring batch job.

package com.roytuts.spring.batch;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = "com.roytuts.spring.batch")
public class SpringBatch {
	public static void main(String[] args) {
		SpringApplication.run(SpringBatch.class, args);
	}
}

Testing the Application

Run the above class, you will see the below output for spring batch quartz scheduler example.

15:09:20.064  INFO 17656 --- [           main] org.quartz.impl.StdSchedulerFactory      : Using default implementation for ThreadExecutor
15:09:20.093  INFO 17656 --- [           main] org.quartz.core.SchedulerSignalerImpl    : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
15:09:20.094  INFO 17656 --- [           main] org.quartz.core.QuartzScheduler          : Quartz Scheduler v.2.3.1 created.
15:09:20.097  INFO 17656 --- [           main] org.quartz.simpl.RAMJobStore             : RAMJobStore initialized.
15:09:20.100  INFO 17656 --- [           main] org.quartz.core.QuartzScheduler          : Scheduler meta-data: Quartz Scheduler (v2.3.1) 'schedulerFactoryBean' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
15:09:20.101  INFO 17656 --- [           main] org.quartz.impl.StdSchedulerFactory      : Quartz scheduler 'schedulerFactoryBean' initialized from an externally provided properties instance.
15:09:20.101  INFO 17656 --- [           main] org.quartz.impl.StdSchedulerFactory      : Quartz scheduler version: 2.3.1
15:09:20.104  INFO 17656 --- [           main] org.quartz.core.QuartzScheduler          : JobFactory set to: [email protected]2
15:09:20.490  INFO 17656 --- [           main] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now
15:09:20.491  INFO 17656 --- [           main] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_NON_CLUSTERED started.
15:09:20.508  INFO 17656 --- [           main] com.roytuts.spring.batch.SpringBatch     : Started SpringBatch in 3.603 seconds (JVM running for 4.295)
15:09:20.511  INFO 17656 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
15:09:20.629  INFO 17656 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{run.id=1}]
15:09:20.671  INFO 17656 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:20.805  INFO 17656 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED]
15:09:22.044  INFO 17656 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949962027}]
15:09:22.065  INFO 17656 --- [ryBean_Worker-1] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:22.120  INFO 17656 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949962027}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:24.010  INFO 17656 --- [ryBean_Worker-2] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949964001}]
15:09:24.024  INFO 17656 --- [ryBean_Worker-2] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:24.069  INFO 17656 --- [ryBean_Worker-2] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949964001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:26.009  INFO 17656 --- [ryBean_Worker-3] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949966002}]
15:09:26.019  INFO 17656 --- [ryBean_Worker-3] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:26.065  INFO 17656 --- [ryBean_Worker-3] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949966002}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:28.129  INFO 17656 --- [ryBean_Worker-4] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949968109}]
15:09:28.158  INFO 17656 --- [ryBean_Worker-4] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:28.246  INFO 17656 --- [ryBean_Worker-4] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949968109}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:30.008  INFO 17656 --- [ryBean_Worker-5] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949970001}]
15:09:30.017  INFO 17656 --- [ryBean_Worker-5] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:30.087  INFO 17656 --- [ryBean_Worker-5] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949970001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:32.009  INFO 17656 --- [ryBean_Worker-6] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949972002}]
15:09:32.021  INFO 17656 --- [ryBean_Worker-6] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:32.073  INFO 17656 --- [ryBean_Worker-6] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949972002}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:34.006  INFO 17656 --- [ryBean_Worker-7] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949974001}]
15:09:34.015  INFO 17656 --- [ryBean_Worker-7] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:34.058  INFO 17656 --- [ryBean_Worker-7] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949974001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:36.006  INFO 17656 --- [ryBean_Worker-8] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949976001}]
15:09:36.014  INFO 17656 --- [ryBean_Worker-8] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:36.049  INFO 17656 --- [ryBean_Worker-8] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949976001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:38.006  INFO 17656 --- [ryBean_Worker-9] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949978001}]
15:09:38.013  INFO 17656 --- [ryBean_Worker-9] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:38.047  INFO 17656 --- [ryBean_Worker-9] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949978001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:40.017  INFO 17656 --- [yBean_Worker-10] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949980002}]
15:09:40.031  INFO 17656 --- [yBean_Worker-10] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:40.086  INFO 17656 --- [yBean_Worker-10] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949980002}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:42.006  INFO 17656 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949982000}]
15:09:42.015  INFO 17656 --- [ryBean_Worker-1] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:42.063  INFO 17656 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949982000}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:44.008  INFO 17656 --- [ryBean_Worker-2] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949984001}]
15:09:44.019  INFO 17656 --- [ryBean_Worker-2] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:44.060  INFO 17656 --- [ryBean_Worker-2] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949984001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
15:09:46.005  INFO 17656 --- [ryBean_Worker-3] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] launched with the following parameters: [{timestamp=1558949986001}]
15:09:46.013  INFO 17656 --- [ryBean_Worker-3] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
Processing: Person [id=1000, firstName=soumitra, lastName=roy]
Processing: Person [id=1001, firstName=souvik, lastName=sanyal]
Processing: Person [id=1002, firstName=arup, lastName=chatterjee]
Processing: Person [id=1003, firstName=suman, lastName=mukherjee]
Processing: Person [id=1004, firstName=debina, lastName=guha]
Processing: Person [id=1005, firstName=liton, lastName=sarkar]
Processing: Person [id=1006, firstName=debabrata, lastName=poddar]
15:09:46.056  INFO 17656 --- [ryBean_Worker-3] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=jobCsvXml]] completed with the following parameters: [{timestamp=1558949986001}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done

In the above output you see the job name, step name and also which row item from csv file is being processed.

You see also from the above output that the step1 has been executed repeatedly until you stop the execution of the task.

You also see the sql scripts have been executed and below tables have been created in the MySQL database with job details for spring batch quartz scheduler.

spring batch quartz scheduler

You will also see the above tables have been populated automatically with their status, job name, version etc.

That’s all. Hope you have understood spring batch quartz scheduler example. In real application you might handle much more complex situation but here you got only a concept of it.

Source Code

Thanks for reading.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *