Results 1 to 4 of 4

Thread: Accessing job execution context from ItemWriter

  1. #1
    Join Date
    Dec 2010
    Posts
    175

    Question 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. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    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).

  3. #3
    Join Date
    Dec 2010
    Posts
    175

    Question

    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
    		
    	}
    
    }

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •