Announcement Announcement Module
Collapse
No announcement yet.
Making ItemReader threadsafe Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making ItemReader threadsafe

    How do we make the StoredProcedureItemReader thread-safe?

  • #2
    You can synchronize the read() method (e.g. by wrapping it in a delegator that does the synchronization). Remember that you will lose restartability, so best practice is to mark the step as not restartable and to be safe (and efficient) you can also set saveState=false on the reader.

    Comment


    • #3
      Multi thread fails...

      I am running the StoredProcedureItemReader in a multithreaded fasion. I get the below error
      Encountered an error executing the step
      org.springframework.dao.InvalidDataAccessResourceU sageException: Unexpected cursor position change.

      when I run in single threaded mode I dont have this issue....

      Comment


      • #4
        I am using the spring class StoredprocedureItemReader....How do i synchronise the read method then?

        Comment


        • #5
          Did you try my original suggestion: "wrapping it in a delegator that does the synchronization"?

          Comment


          • #6
            Im not sure how to do that...is there an example you can point to? Thanks a lot...

            Comment


            • #7
              How about this:

              Code:
              public SynchronizedItemReader<T> implements ItemReader<T> {
                private final ItemReader<T> delegate; 
                public SynchronizedItemReader(ItemReader<T> delegate) {
                  this.delegate = delegate;
                }
                public synchronized T read () {
                  return delegate.read();
                }
              }

              Comment


              • #8
                When I use the synchronisedItemReader, I get reader must be open to read exception.
                org.springframework.batch.item.ReaderNotOpenExcept ion: Reader must be open before it can be read.

                Comment


                • #9
                  Im really stuck on a dead end..Could someone please review?

                  Comment


                  • #10
                    I implemented the open and close in my itemreader and it worked. Thanks for your help Dave..

                    Comment

                    Working...
                    X