Announcement Announcement Module
No announcement yet.
How to access StepExecutionContext from the reader Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access StepExecutionContext from the reader

    I have a requirement to store the data read in the reader in the job execution context so that it is accessible to the other steps. Is it possible to access step execution context in the read method of the reader and then promote the data in step execution context to job execution context? Is there any listener which has access to both the data returned by the reader and the step/job execution context?

    Thanks in advance.

  • #2
    There's an ExecutionContextPromotionListener for that use case. Be careful how much data you store there because it is persisted in the JobRepository.


    • #3
      In my case the first step is a partition step and each partition has the same key in its execution context. How can i promote the values in all the partitions to the job execution context(as a list or an array).

      Can I do this explicitly in the afterStep method of ExecutionContextPromotionListener listener? Is that the preferred approach? My assumption here is that the listener will be invoked after the completion of each partition.

      Below is the pseudo code I am planning to use:

      public ExitStatus afterStep(StepExecution stepExecution){
      ExecutionContext stepExecutionContext = stepExecution.getExecutionContext();
      ExecutionContext jobExecutionContext = stepExecution.getJobExecution().getExecutionContex t();

      String value = stepExecutionContext.get("key");
      List valueList = jobExecutionContext.get("key");
      List valueList = new ArrayList();
      return super.afterStep(stepExecution);

      Please let me know if there are alternate approaches to this.
      Last edited by Bhuvana; Jul 29th, 2010, 06:47 AM.


      • #4
        I tried a sample job with the above contextlistener but it looks like the listener is getting invoked only once. I am not sure this is because of the exit status being returned by the afterStep method. Is there a specific exit status I need to return so that the execution will still be for the current step until the listener is invoked for all the partition steps?

        Please help since this is holding up my work.


        • #5
          Any working model for this ?


          • #6
            The super class return null, so the ExitStatus is not a problem. The problem might be that since you are using a partition step, so you are overwriting JobExecution context entries - each partition adds its own data to the same keys. You would need to make the keys unique in the JobExecution maybe by adding the step name as a prefix.