Announcement Announcement Module
Collapse
No announcement yet.
Accessing job execution context from ItemWriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing job execution context from ItemWriter

    Hi,

    I did read some post which looked similar but I think they may not have the same requirement.

    I would like to get hold of job execution context from my custom item Writer Listener. So that in the onWriteError() I can add failed items list to the context and use them later in job execution listener.

    Any ideas????

  • #2
    you can implement StepExecutionListener to store the StepExecution as a property in the ItemWriter. Be careful not to store too much inside the context. The ItemWriter will be then statefull, so not threadsafe anymore (perhaps it wasn't anyway).

    Comment


    • #3
      Okay. This is what I already thought so and read in older posts. However, I'm not sure what happens at runtime:

      Will this listener get executed on both item write event and step events?


      Code:
      public class CustomeItemWriteListener implements ItemWriteListener<S>,
      		StepExecutionListener {
      
      	public ExitStatus afterStep(StepExecution arg0) {
      		// TODO Auto-generated method stub
      		return null;
      	}
      
      	public void beforeStep(StepExecution arg0) {
      		// TODO Auto-generated method stub
      
      	}
      
      	public void afterWrite(List<? extends S> arg0) {
      		// TODO Auto-generated method stub
      		
      	}
      
      	public void beforeWrite(List<? extends S> arg0) {
      		// TODO Auto-generated method stub
      		
      	}
      
      	public void onWriteError(Exception arg0, List<? extends S> arg1) {
      		// TODO Auto-generated method stub
      		
      	}
      
      }

      Comment


      • #4
        Will this listener get executed on both item write event and step events?
        yes. You can try by logging the calls.

        Comment

        Working...
        X