spring-batch

How to set up multi-threading in Spring Batch?

巧了我就是萌 提交于 2019-11-27 13:18:17
I've successfully set up a tutorial Spring Batch project. I'd really like to know if it's possible to make it multi-threaded at the "Spring level". The basic idea of what I want is to make a list of tasks or task steps and let them be picked up and worked on by independent threads, ideally out of a pool limited to 'n' number of threads. Is this possible? If so, how? Could someone show guide me to that point from where I'm currently at? The simple project I have is from this tutorial here . It basically has different tasks which print out a message to the screen. Here's my current simpleJob.xml

Spring-batch @BeforeStep does not work with @StepScope

柔情痞子 提交于 2019-11-27 12:46:48
I'm using Spring Batch version 2.2.4.RELEASE I tried to write a simple example with stateful ItemReader, ItemProcessor and ItemWriter beans. public class StatefulItemReader implements ItemReader<String> { private List<String> list; @BeforeStep public void initializeState(StepExecution stepExecution) { this.list = new ArrayList<>(); } @AfterStep public ExitStatus exploitState(StepExecution stepExecution) { System.out.println("******************************"); System.out.println(" READING RESULTS : " + list.size()); return stepExecution.getExitStatus(); } @Override public String read() throws

Storing in JobExecutionContext from tasklet and accessing in another tasklet

本小妞迷上赌 提交于 2019-11-27 11:23:14
I have a requirement in which a tasklet, stores all the files in the directories in an arraylist. The size of the list is stored in the job execution context. Later this count is accessed from another tasklet in another step. How do it do this. I tried to store in jobexecution context, at runtime throws unmodifiable collection exception, public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception { StepContext stepContext = arg1.getStepContext(); StepExecution stepExecution = stepContext.getStepExecution(); JobExecution jobExecution = stepExecution.getJobExecution();

Define an in-memory JobRepository

谁说我不能喝 提交于 2019-11-27 09:21:39
I'm testing Spring Batch using Spring boot. My need is to define jobs working on an Oracle Database but I don't want to save jobs and steps states inside this DB. I've read in the documentation I can use a in-memory repository with the MapJobRepositoryFactoryBean. Then, I've implemented this bean: @Bean public JobRepository jobRepository() { MapJobRepositoryFactoryBean factoryBean = new MapJobRepositoryFactoryBean(new ResourcelessTransactionManager()); try { JobRepository jobRepository = factoryBean.getObject(); return jobRepository; } catch (Exception e) { e.printStackTrace(); return null; }

Spring Batch ORA-08177: can't serialize access for this transaction when running single job, SERIALIZED isolation level

你说的曾经没有我的故事 提交于 2019-11-27 07:51:34
I am getting this exception with SERIALIZED isolation level on JobRepository in Spring Batch: org.springframework.dao.CannotSerializeTransactionException: PreparedStatementCallback; SQL [INSERT into DATAFEED_APP.BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; ORA-08177: can't serialize access for this transaction ; nested exception is java.sql.SQLException: ORA-08177: can't serialize access for this transaction at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:269) at org

How to run spring batch jobs in parallel

别说谁变了你拦得住时间么 提交于 2019-11-27 07:17:45
问题 I have a job flow and I would like to run it as the following: Job1 -> Job2 -> Job3 -> Job4 -> Job5 The job flow will be started from Job1. After Job1 is successfully finished, Job1 will launch both Job2 and Job4. Job2 and Job4 will run in parallel. After Job2 is successfully finished, Job2 will launch Job3. After Job4 is successfully finished, Job4 will launch Job5. The following is the code snippet for job1.xml and job launcher class of Job1: job1.xml <bean id="uiJobListener" class="com

Can we write a Spring Batch Job Without ItemReader and ItemWriter

ぃ、小莉子 提交于 2019-11-27 07:09:43
问题 In my project, I have written a Quartz scheduler with Spring Batch 2.2. As per my requirement, I want to run a scheduler to fetch application config property to refresh the configuration cache on all the GlassFish Clusters. So I dont need ItemWriter and ItemReader which are used to for File Read/Write operations. So can I remove ItemReader and ItemWriter from ? The configuration of my job is mentioned below : <batch:job id="reportJob"> <batch:step id="step1"> <batch:tasklet> <!--I want to

Multi-threaded acces to Job Scope beans in Spring Batch 3.0

你离开我真会死。 提交于 2019-11-27 06:02:29
问题 In Spring Batch 3.0 I'm trying to use the new Job Scope functionality for beans in both partitioned and multi-threaded steps (configured with an task:executor bean), and in both cases I'm getting the exception Caused by: java.lang.IllegalStateException: No context holder available for job scope at org.springframework.batch.core.scope.JobScope.getContext(JobScope.java:153) at org.springframework.batch.core.scope.JobScope.get(JobScope.java:92) at org.springframework.beans.factory.support

Difference between spring batch remote chunking and remote partitioning

别来无恙 提交于 2019-11-27 04:16:10
What is the difference between spring batch remote chunking and remote partitioning? I can not understand the difference between remote chunking and remote partitioning in spring batch. Could anybody please explain? Remote Partitioning Partitioning is a master/slave step configuration that allows for partitions of data to be processed in parallel. Each partition is described via some metadata. For example, if you were processing a database table, partition 1 may be ids 0-100, partition 2 being 101-200, etc. For Spring Batch, a master step uses a Partitioner to generate ExecutionContexts that

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]

痞子三分冷 提交于 2019-11-27 03:54:12
Situation I am using Spring Batch to build an Accumulative Snapshot for our Data Warehouse and I am having a configuration roadblock that I cannot figure out. I have created a Simple Spring Batch Project with STS (SpringSource Tool Suite 2.8.1) using the Spring Template Project . These were my two xml configuration files created: launch-context.xml <?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" xmlns:context="http://www