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 with some modification 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.

You can read also how to read csv file and write to xml file using spring batch.

What we will do

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 Quartz Scheduler.

Prerequisites

Eclipse

Maven 3.2.1

JDK 1.8

Spring Batch and MySQL connector dependencies in pom.xml file

Step 1. Create Maven project(standalone or quickstart) in Eclipse IDE and necessary project structure gets created.

Group Id: com.roytuts

Artifact Id: spring-batch

Step 2. Modify pom.xml file so that it looks like below.

It downloads all jars from maven repository.

We need to add Quartz API and spring-context-support dependencies additionally and other required dependencies.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.roytuts</groupId>
	<artifactId>spring-batch</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>spring-batch</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
		<spring.version>4.3.5.RELEASE</spring.version>
		<spring.batch.version>3.0.7.RELEASE</spring.batch.version>
		<mysql.version>5.1.27</mysql.version>
		<quartz.version>2.2.3</quartz.version>
	</properties>

	<dependencies>
		<!-- spring core -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- spring context -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- spring batch -->
		<dependency>
			<groupId>org.springframework.batch</groupId>
			<artifactId>spring-batch-core</artifactId>
			<version>${spring.batch.version}</version>
		</dependency>

		<!-- spring XML to Java or vice versa -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- Quartz framework -->
		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
			<version>${quartz.version}</version>
		</dependency>

		<!-- spring jdbc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- mysql driver -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>${mysql.version}</version>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>3.0.0</version>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.directory}/spring-batch/</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

Step 3. 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.model;

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 + "]";
	}

}

Step 4. 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.mapper;

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

import com.roytuts.spring.batch.model.Person;

public class PersonFieldSetMapper implements FieldSetMapper<Person> {

	@Override
	public Person mapFieldSet(FieldSet fieldSet) throws BindException {
		Person person = new Person();
		person.setId(fieldSet.readInt(0));
		person.setFirstName(fieldSet.readString(1));
		person.setLastName(fieldSet.readString(2));
		return person;
	}

}

Step 5. 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.processor;

import org.springframework.batch.item.ItemProcessor;

import com.roytuts.spring.batch.model.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;
	}

}

Step 6. 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

Step 7. 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.schedule;

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 QuartzTaskScheduler 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");
	}

}

Step 8. Create below spring config XML files under src/main/resources directory for spring batch quartz scheduler example.

spring-beans.xml

This file defines beans for Person class and PersonItemProcessor class.

<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

	<bean id="person" class="com.roytuts.spring.batch.model.Person"
		scope="prototype" />

	<bean id="itemProcessor" class="com.roytuts.spring.batch.processor.PersonItemProcessor"
		scope="prototype" />

</beans>

spring-datasource.xml

This file defines the bean for spring datasource. It also initializes the database for automatically creating spring batch job meta tables in MySQL database.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/jdbc
	http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/roytuts" />
		<property name="username" value="root" />
		<property name="password" value="" />
	</bean>

	<!-- create job-meta tables automatically -->
	<jdbc:initialize-database data-source="dataSource">
		<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" />
		<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
	</jdbc:initialize-database>

</beans>

spring-batch.xml

This files defines beans for spring batch job, csv file reader, xml file writer, jaxb marshaller, job repository, transaction manager, job launcher.

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.

A 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.

transaction-manager – Spring’s PlatformTransactionManager that will be used to begin and commit transactions during processing.

commit-interval – The number of items that will be processed before the transaction is committed.

The Tasklet is a simple interface that has one method, execute, which will be a called repeatedly by the TaskletStep until it either returns RepeatStatus.FINISHED or throws an exception to signal a failure. Each call to the Tasklet is wrapped in a transaction. Tasklet implementors might call a stored procedure, a script, or a simple SQL update statement. To create a TaskletStep, the ‘ref’ attribute of the <tasklet/> element should reference a bean defining a Tasklet object; no <chunk/> element should be used within the <tasklet/>

JobRepository is the persistence mechanism. It provides CRUD operations for JobLauncher, Job, 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.

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

A batch namespace has been provided for ease of configuration and as long as the batch namespace has been declared, any of its elements can be used.

<scheduled-task/> has been used to schedule the task repeatedly using cron expression. For more on cron expression please go through https://docs.oracle.com/cd/E14003_01/doc/doc.1014/e12030/cron_expressions.htm

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

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch"
	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/batch
           http://www.springframework.org/schema/batch/spring-batch.xsd
           http://www.springframework.org/schema/task
           http://www.springframework.org/schema/task/spring-task.xsd">

	<beans:import resource="classpath:spring-datasource.xml" />
	<beans:import resource="classpath:spring-beans.xml" />

	<job id="ioSampleJob">
		<step id="step1">
			<tasklet transaction-manager="transactionManager">
				<chunk reader="cvsFileItemReader" writer="xmlItemWriter"
					processor="itemProcessor" commit-interval="2" />
			</tasklet>
		</step>
	</job>

	<beans:bean id="cvsFileItemReader"
		class="org.springframework.batch.item.file.FlatFileItemReader">
		<beans:property name="resource" value="classpath:person.csv" />
		<beans:property name="lineMapper">
			<beans:bean
				class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
				<beans:property name="lineTokenizer">
					<beans:bean
						class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
						<beans:property name="names" value="id,firstName,lastName" />
					</beans:bean>
				</beans:property>
				<beans:property name="fieldSetMapper">
					<beans:bean class="com.roytuts.spring.batch.mapper.PersonFieldSetMapper" />
				</beans:property>
			</beans:bean>
		</beans:property>
	</beans:bean>

	<beans:bean id="xmlItemWriter"
		class="org.springframework.batch.item.xml.StaxEventItemWriter">
		<beans:property name="resource" value="file:xml/person.xml" />
		<beans:property name="marshaller" ref="personMarshaller" />
		<beans:property name="rootTagName" value="personInfo" />
	</beans:bean>

	<beans:bean id="personMarshaller"
		class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
		<beans:property name="classesToBeBound">
			<beans:list>
				<beans:value>com.roytuts.spring.batch.model.Person</beans:value>
			</beans:list>
		</beans:property>
	</beans:bean>

	<!-- stored job-meta in database -->
	<beans:bean id="jobRepository"
		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
		<beans:property name="dataSource" ref="dataSource" />
		<beans:property name="transactionManager" ref="transactionManager" />
		<beans:property name="databaseType" value="mysql" />
	</beans:bean>

	<beans:bean id="transactionManager"
		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

	<beans:bean id="jobLauncher"
		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
		<beans:property name="jobRepository" ref="jobRepository" />
	</beans:bean>
	
	<beans:bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
		<beans:property name="jobRegistry" ref="jobRegistry" />
  	</beans:bean>
 
  	<beans:bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
  	
  	<!-- run every 10 seconds using quartz api -->
	  <beans:bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<beans:property name="triggers">
		  <beans:bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
			<beans:property name="jobDetail" ref="jobDetail" />
			<beans:property name="cronExpression" value="*/10 * * * * ?" />
		  </beans:bean>
		</beans:property>
	  </beans:bean>
	  
	  <beans:bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
	  	<beans:property name="jobClass" value="com.roytuts.spring.batch.schedule.QuartzTaskScheduler"></beans:property>
	  	<beans:property name="jobDataAsMap">
	  		<beans:map>
	  			<beans:entry key="jobName" value="ioSampleJob"></beans:entry>
	  			<beans:entry key="jobLauncher" value-ref="jobLauncher"></beans:entry>
	  			<beans:entry key="jobLocator" value-ref="jobRegistry"></beans:entry>
	  		</beans:map>
	  	</beans:property>
	  </beans:bean>

</beans:beans>

Step 9. Create below class for launching spring batch quartz scheduler.

package com.roytuts.spring.batch.runner;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringBatchRunner {

	public static void main(String[] args) {
		new ClassPathXmlApplicationContext(new String[] { "spring-batch.xml" });
	}

}

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

Jan 18, 2017 7:51:21 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7c5b4: startup date [Wed Jan 18 07:51:21 IST 2017]; root of context hierarchy
Jan 18, 2017 7:51:21 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-batch.xml]
Jan 18, 2017 7:51:21 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-datasource.xml]
Jan 18, 2017 7:51:21 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-beans.xml]
Jan 18, 2017 7:51:21 AM org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'jobRegistry' of type [class org.springframework.batch.core.configuration.support.MapJobRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Jan 18, 2017 7:51:21 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Jan 18, 2017 7:51:21 AM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executing SQL script from class path resource [org/springframework/batch/core/schema-drop-mysql.sql]
Jan 18, 2017 7:51:22 AM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executed SQL script from class path resource [org/springframework/batch/core/schema-drop-mysql.sql] in 482 ms.
Jan 18, 2017 7:51:22 AM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executing SQL script from class path resource [org/springframework/batch/core/schema-mysql.sql]
Jan 18, 2017 7:51:23 AM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executed SQL script from class path resource [org/springframework/batch/core/schema-mysql.sql] in 1005 ms.
Jan 18, 2017 7:51:23 AM org.springframework.oxm.jaxb.Jaxb2Marshaller createJaxbContextFromClasses
INFO: Creating JAXBContext with classes to be bound [class com.roytuts.spring.batch.model.Person]
Jan 18, 2017 7:51:23 AM org.springframework.batch.core.launch.support.SimpleJobLauncher afterPropertiesSet
INFO: No TaskExecutor has been set, defaulting to synchronous executor.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jan 18, 2017 7:51:23 AM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase 2147483647
Jan 18, 2017 7:51:23 AM org.springframework.scheduling.quartz.SchedulerFactoryBean startScheduler
INFO: Starting Quartz Scheduler now
Jan 18, 2017 7:51:30 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] launched with the following parameters: [{timestamp=1484706090009}]
Jan 18, 2017 7:51:30 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: 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]
Jan 18, 2017 7:51:30 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] completed with the following parameters: [{timestamp=1484706090009}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
Jan 18, 2017 7:51:40 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] launched with the following parameters: [{timestamp=1484706100002}]
Jan 18, 2017 7:51:40 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: 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]
Jan 18, 2017 7:51:40 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] completed with the following parameters: [{timestamp=1484706100002}] and the following status: [COMPLETED]
Job Status : COMPLETED
Done
Jan 18, 2017 7:51:50 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] launched with the following parameters: [{timestamp=1484706110007}]
Jan 18, 2017 7:51:50 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: 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]
Jan 18, 2017 7:51:50 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=ioSampleJob]] completed with the following parameters: [{timestamp=1484706110007}] 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.

Thanks for reading.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

Leave a Reply

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