Announcement Announcement Module
Collapse
No announcement yet.
rollback mechanism for chunk oriented processing strategy of Spring Batch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • rollback mechanism for chunk oriented processing strategy of Spring Batch

    Hello,

    As we all know, spring batch uses chunk oriented processing since the version 2.0.

    Does it mean that, if an exception occurs in the item writer, the Data Source Transaction manager will roll back the whole chunk or only the related item?

    Actually, I gave it a try and saw that the framework rolls back the whole chunk. That's not what I need because I do not want, let's say, 499 items which have been processed successfully to be rolled back in a chunk consisting of 500 items when the last item causes an exception to be thrown.

    Maybe Spring Batch is not suitable for my problem domain. If so, please tell me so I won't be struggling with those kind of framework specific behaviour anymore.

    Any suggestions would be greatly appreciated.

  • #2
    Kivanc,

    I might be missing something. If you want to be able to roll back individual items, why is your chunk size 500 instead of 1? Granted, the job will be slower but you will get the granularity you are looking for.

    Comment


    • #3
      That's a very good question and I think you're right about reducing the chunk size to 1.

      However, what I want to achieve is to read chunks of data from the database while treating them individually in terms of rollback.

      Actually, after having posted this thread, I found something, but I am not sure if this is the right way.

      I added the following attribute to the tasklet and the job does exactly what I want it to do.
      Code:
      <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
      I really need your opinions about that.

      Regards

      Comment


      • #4
        what about skipping the error? assuming the to-be-skipped exception is thrown in the writer, Spring Batch would then rollback the chunk and write each item of the chunk one-by-one (in separate transactions) to find the item that threw the exception.

        Comment


        • #5
          I tried adding <skippable-exception-classes> to the chunk but it didn't work like you expected it to be. It pretends like the exception has never been thrown and it does NOT rollback the chunk and write each item of the chunk one-by-one, unfortunately.

          Comment


          • #6
            silly question perhaps, but did you remove

            Code:
            <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
            ?

            Comment


            • #7
              In my previous post, I had written "I added the following attribute to the tasklet and the job does exactly what I want it to do.". Then I realized that was not true, not at all After spending so much time about this problem, I guess I was feeling dizzy at that moment and thought that I found the solution

              Anyway, I definitely removed
              <CODE>
              <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
              </CODE>

              Comment

              Working...
              X