Spring batch_multi-threaded STEP_ using multi-threaded Step

Source: Internet
Author: User

Spring batch_multi-threaded STEP_ using multi-threaded Step

Spring Official Document: http://docs.spring.io/spring-batch/trunk/reference/html/scalability.html

The simplest-to-start parallel processing is to add a taskexecutor-your Step configuration, e.g. as an attribute of The Tasklet:

<step id= "Loading" > <tasklet task-executor= "taskexecutor" >...</tasklet></step>

In this example the Taskexecutor are a reference to another bean definition, implementing the Taskexecutor interface. Taskexecutor is a standard spring interface, so consult (consult, reference) the Spring User Guide for details of available Implementati Ons. The simplest multi-threaded taskexecutor is a simpleasynctaskexecutor.


The result of the above configuration would be is that the Step executes by reading, processing and writing chunk of items (each commit interval) note that this means there was no fixed order for the items to being processed, and a chunk might contain items that was non- Consecutive (discontinuous) compared to the single-threaded case. In addition to any limits placed by the task executor (e.g. if it's backed by a thread pool), there is a throttle limit I n the Tasklet configuration which defaults to 4. Need to increase this to ensure, the thread pool is fully utilised, e.g.

<step id= "Loading" > <tasklet task-executor= "taskexecutor" throttle-limit= [>...</tasklet></] Step>

Note also that there is limits placed on concurrency by any pooled resources used in your step, such as a DataSource. Be sure to make the pool in those resources at least as large as the desired number of concurrent threads in the step.


There is some practical limitations of using multi-threaded Steps for some common Batch use cases. Many participants in a Step (e.g. readers and writers) Is stateful (stateful), and if the state was not segregated (separated, separated) by thread, then those, which is not usable in a multi- Threaded Step. in particular most of the off-the-shelf (off-the-shelf) readers and writers from Spring Batch is not designed for multi-threaded us E. It is, however, possible to work with stateless or thread safe readers and writers, and the Re is a sample (Paralleljob) in the Spring Batch Samples This show the use of a process indicator (see section 6.12, "Prev Enting state persistence ") to keep track of items has been processed in a database input table.


Spring Batch provides some implementations of Itemwriter and Itemreader. usually they say in the Javadocs if they is thread safe or not, Or what, have the to does to avoid problems in a concurrent environment. If there is no information in Javadocs, you can check the implementation to see if there are any state. If a reader is not the thread safe, it may still be efficient (efficient) to the use of it in your own synchronizing delegator. You can synchronize the call to read () and as long as the processing and writing are the most expensive part of the CH UNK your step may still complete much faster than in a single threaded configuration.


=================end=================


Spring batch_multi-threaded STEP_ using multi-threaded Step

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.