Is Spring Batch ItemWriter a singleton class?

I have a batch job with the following definition:

<batch:job id="job">
    <batch:split id="main" task-executor="simpleAsyncTaskExecutor">
        <batch:flow>
            <batch:step id="getAccountDetails">
                <batch:tasklet ref="getAccountDetailsTasklet"/>
            </batch:step>
        </batch:flow>
        <batch:flow>
            <batch:step id="processAccounts">
                <batch:tasklet transaction-manager="transactionManager" task-executor="threadPoolTaskExecutor" throttle-limit="${processor.maxThreads}">
                    <batch:chunk reader="queueReader" writer="myCustomItemWriter" commit-interval="${processor.commitInterval}"/>
                </batch:tasklet>
            </batch:step>
        </batch:flow>
    </batch:split>
</batch:job>

myCustomItemWriter basically goes through the list of accounts passed through queueReader and writes them to the database.

The task is scaled to simultaneously launch 100 threads of this fragment. In the myCustomItemWriter class, I have a private property that supports the sum of the specific BigDecimal property for each account that it processes. Therefore, if there are 10,000 accounts, I will have 100 threads, each of which will process 100 accounts. I want to capture the sum of this property for all of these 10,000 accounts.

: ItemWriter singleton ( )? , AtomicReference bean , 100 ?

+4
1

@Component, .

, XML-, . , : job step.

CustomItemWriter @Scope("step"), , , myCustomItemWriter, .

+1

Source: https://habr.com/ru/post/1621739/


All Articles