Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6800591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:59:17+00:00 2026-05-26T18:59:17+00:00

I have a requirement in which a tasklet, stores all the files in the

  • 0

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();
    ExecutionContext jobContext = jobExecution.getExecutionContext();
     jobContext.put("FILE_COUNT",150000);

also stored the stepexection reference in beforestep annotation .still not possioble.kindly let me know ,how to share data between two tasklets.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:59:18+00:00Added an answer on May 26, 2026 at 6:59 pm

    you have at least 4 possibilities:

    1. use the ExecutionPromotionListener to pass data to future steps
    2. use a (spring) bean to hold inter-step data, e.g. a ConcurrentHashMap
      • without further action this data won’t be accessible for a re-start
    3. access the JobExecutionContext in your tasklet, should be used with caution, will cause thread problems for parallel steps
    4. use the new jobscope (introduced with spring batch 3)

    Code Example for accessing JobExecution from Tasklet:

    1. setting a value

      public class ChangingJobExecutionContextTasklet implements Tasklet {
      
          /** {@inheritDoc} */
          @Override
          public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
              // set variable in JobExecutionContext
              chunkContext
                      .getStepContext()
                      .getStepExecution()
                      .getJobExecution()
                      .getExecutionContext()
                      .put("value", "foo");
      
              // exit the step
              return RepeatStatus.FINISHED;
          }
      
      }
      
    2. extracting a value

      public class ReadingJobExecutionContextTasklet implements Tasklet {
      
          private static final Logger LOG = LoggerFactory.getLogger(ChangingJobExecutionContextTasklet.class);
      
          /** {@inheritDoc} */
          @Override
          public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
              // pull variable from JobExecutionContext
              String value = (String) chunkContext
                                          .getStepContext()
                                          .getStepExecution()
                                          .getJobExecution()
                                          .getExecutionContext()
                                          .get("value");
      
              LOG.debug("Found value in JobExecutionContext:" + value);
      
              // exit the step
              return RepeatStatus.FINISHED;
          }
      }
      

    i created code examples for the first 3 solutions in my spring-batch-examples github repository, see module complex and package interstepcommunication

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a requirement in which i will retrieve all the records from the
I have a weird requirement which I need to use inside my Stored Procedure
I have a requirement which sounds like kind of simple but hard to implement
Good day, I have a requirement which i need to include a layout (actually
I have a unique requirement which I need to meet to with sitecore, and
I have a data storage requirement which is an excellent candidate for single instance
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have a requirement to design an application which notifies/publishes, its subsystems to send
I have a requirement to design a Web Application which acts as a Facade
I have a requirement to create a windows form control which has to detect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.