Results 1 to 3 of 3

Thread: SkipListener /ItemWriteLiserner not being called.

  1. #1

    Default SkipListener /ItemWriteLiserner not being called.

    Hi All

    I configured a skip Listener for a step and it doesn't seem like it is working.
    I am introducing an error during write. As I would expect, since transaction is rolled back the chunk is not written to the database. However, i was expecting to see this listener being called so that I could capture what was not written to the database. It doesn't get called. I also tried using a ItemWriteListener which was not called either. what am I doing wrong

    Here is my listener class:

    Public class BPMSkipListener implements SkipListener {

    @Override
    public void onSkipInProcess(Object arg0, Throwable arg1) {
    // TODO Auto-generated method stub

    System.out.println(" process skip");
    }

    @Override
    public void onSkipInRead(Throwable arg0) {
    // TODO Auto-generated method stub
    System.out.println(" Read skip");

    }

    @Override
    public void onSkipInWrite(Object arg0, Throwable arg1) {
    // TODO Auto-generated method stub
    System.out.println(" Record Skipped :"+arg0.toString()+" = Error:"+arg1);

    }


    and here is the step configuration:

    <step id="gameLoad" next="playerSummarization" >
    <tasklet transaction-manager="bpmTransactionManager" >
    <chunk reader="gameFileItemReader" writer="gameWriter"
    commit-interval="${job.commit.interval}" skip-limit="10">

    <skippable-exception-classes>
    <include class="java.lang.Exception"/>
    </skippable-exception-classes>
    </chunk>

    <listeners>
    <listener ref="bpmSkipListener"/>
    </listeners>

    </tasklet>

    </step>




    <bean id="bpmSkipListener" class="com.xxxxxx.bpm.batch.base.BPMItemWriteListe ner"/>

  2. #2
    Join Date
    Jul 2011
    Posts
    15

    Default

    Hi bleacherseat,

    I think skip listeners are only called when the transaction of the chunk is commited. This is because if there is a rollback you don't really have written the chunk yet , so you don't want to log already the skipped element because something can go wrong after the rollback and the chunk could be never be written.

    Maybe you could use the @OnWriteError listener and identify the skippable exceptions to log in this method.

    Hope this help you.

  3. #3

    Default

    i guess you used the listeners element on the wrong part, it works with this config

    Code:
        
       <job id="skipJob" xmlns="http://www.springframework.org/schema/batch">
            <step id="skipJobStep">
                <tasklet>
                    <chunk 
                        reader="itemReader" 
                        writer="itemWriter" 
                        commit-interval="5">
                    </chunk>
                </tasklet>
                <listeners>
                    <listener ref="stepListener" />
                </listeners>            
            </step>
        </job>
    your example would work, if the listener were a chunklistener

Posting Permissions

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