Unable to use Job Scope beans in a multi-threaded or partitioned step [BATCH-2269]
See original GitHub issueDavid Geary opened BATCH-2269 and commented
Attempting to access a JobScope bean from a worker thread in a thread pool as part of a multi-threaded or partitioned step gives the following 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.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:338)
This is due to the fact the JobExecution is stored in a ThreadLocal and it isn’t set up on the worker threads.
Affects: 3.0.1
Reference URL: http://stackoverflow.com/questions/24558703/multi-threaded-acces-to-job-scope-beans-in-spring-batch-3-0
18 votes, 21 watchers
Issue Analytics
- State:
- Created 9 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Multi-threaded acces to Job Scope beans in Spring Batch 3.0
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 ...
Read more >Job Scoped Beans in Spring Batch - Medium
This job scope makes our life easier by ensuring we have a new instance every time a job is invoked and the same...
Read more >Interview QA | Spring Batch Partitioning example | JavaTechie
This tutorial will give you complete picture about How to use spring batch Partitioning to process batch job faster with better performance ...
Read more >Spring Batch Parallel Processing and Scaling 101 - Hevo Data
Multi-Threaded Step ; Parallel Steps; Remote Chunking; Partitioning. Conclusion ... You can use threads to run the partitions in parallel, ...
Read more >Spring Batch partitioned step not running - Anycodings.com
Spring Batch partitioned step not running I was trying to configure my first anycodings_spring-batch multi-threaded ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Carlos Silva commented
We also had this problem, so we define a tweaked TaskExecutor that registers each thread in the JobSynchronizationManager, and in finally it releases it:
Then we use that executor:
If this is not fixed, can we please have the workaround updated in this issue itself? I am facing similar issues. This is the first time we are using Spring batch on our platform, and we will be using multi-threaded steps.
We need a context object for passing some data across steps. The ExecutionContext will not suffice in multithreaded access, as we will require a ‘read-then-update’ pattern (repeatable read isolation reqd). Hence we need our own context with a JobScope - and that is not working for the same reason.