Announcement Announcement Module
Collapse
No announcement yet.
Help needed in using TaskExecutorRepeatTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed in using TaskExecutorRepeatTemplate

    Hi,

    I am a novice in Spring Batch. I have a problem when using TaskExecutorRepeatTemplate. The below sample code snippet is working fine when reading from a file and writing to a console, but it fails when reader is JdbcCursorItemReader and writer is BatchSqlUpdateItemWriter (I am using reader and writer from batchUpdateJob.xml ). The problem is the writer is not flushing the data. Can any one please point out where I am going wrong. Thanks in Advance.

    code snippet:
    TaskExecutorRepeatTemplate template = new TaskExecutorRepeatTemplate();
    template.setTaskExecutor(new SimpleAsyncTaskExecutor());
    template.setThrottleLimit(3);
    TradeWriter writer = new TradeWriter();
    TradeItemReader reader = new TradeItemReader(new ClassPathResource("trades.csv"));
    reader.open(new ExecutionContext());

    final RepeatCallback callback = new ItemReaderRepeatCallback(reader,writer) {
    public ExitStatus doInIteration(RepeatContext context)
    throws Exception {
    return super.doInIteration(context);
    }
    };

    template.iterate(callback);

  • #2
    The problem is the writer is not flushing the data.
    You need to call ItemWriter#flush() - most of the writers write continuously on ItemWriter#write(item) but still need to be flushed to make sure they've written everything, BatchUpdateSqlItemWriter only buffers items on write and physically writes them using batch update when flush() is called.

    Comment


    • #3
      The problem is the writer is not flushing the data.

      Thankyou Robert.

      Comment


      • #4
        some record are not getting updated when ThrottleLimit is set to more than 1

        Robert,

        When I called the flush() method as shown below code snipper, some of the records are not getting updated when the ThrottleLimit is set to anything more than 1.

        public void write(Object data) throws Exception {
        CustomerCredit customerCredit = (CustomerCredit) data;
        customerCredit.increaseCreditBy(FIXED_AMOUNT);
        delegate.write(customerCredit);
        flush();
        }

        Comment


        • #5
          When concurrency is involved you need to use thread-safe readers and writers - while BatchSqlUpdateWriter is thread-safe, JdbcCursorItemReader is not.

          Comment


          • #6
            Do we have any thread-safe readers ?

            Comment


            • #7
              StagingItemReader in samples is the only example so far.

              Comment


              • #8
                Thank you.

                Comment

                Working...
                X