Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Batch : parallel steps execution in java configuration file

Tags:

spring-batch

I am trying to make a sample application on parallel step execution in java configuration file but get perplexed that how many files(job repository,job launcher and execution etc.) are being configured and initialized and if configured then how? Simply I need a sample application to clarify the basics of parallel execution of steps in a job.

like image 414
maddy Avatar asked May 30 '16 07:05

maddy


People also ask

How do you run steps in parallel in Spring Batch?

Parallel Steps The configurable task executor is used to specify which TaskExecutor implementation should be used to execute the individual flows. The default is SyncTaskExecutor , but an asynchronous TaskExecutor is required to run the steps in parallel.

How does multithreading work in Spring Batch?

Multithreaded steps. By default, Spring Batch uses the same thread to execute a batch job from start to finish, meaning that everything runs sequentially. Spring Batch also allows multithreading at the step level. This makes it possible to process chunks using several threads.

How do you get parallelism in a spring boot?

Batch configurationsThe Flow interface is used in spring boot to achieve parallel processing. The Flow interface specifies how and when the batch steps should be executed. The batch flow allows you to choose the order of the batch steps.


1 Answers

Suppose you have steps, A,B1,B2,B3,C. You want to run B1,B2 & B3 in parallel. You first need to create sub-flows for them and then add to one flow with SimpleAsyncTaskExecutor():

@Bean
public Job job()
{
    final Flow flowB1 = new FlowBuilder<Flow>("subflowb1").from(stepb1()).end();
    final Flow flowB2 = new FlowBuilder<Flow>("subflowb2").from(stepb2()).end();
    final Flow flowB3 = new FlowBuilder<Flow>("subflowb3").from(stepb3()).end();

    final Flow splitFlow = new FlowBuilder<Flow>("splitFlow")
        .start(flowB1)
        .split(new SimpleAsyncTaskExecutor())
        .add(flowB2, flowB3).build();

    return jobBuilderFactory
       .flow(stepA())
       .next(splitFlow)
       .next(stepC())
       .end()
       .build();
}
like image 88
Nikhil Pareek Avatar answered Oct 26 '22 10:10

Nikhil Pareek