Results 1 to 8 of 8

Thread: Help needed in using TaskExecutorRepeatTemplate

  1. #1
    Join Date
    May 2008
    Posts
    5

    Default 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. #2

    Default

    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.

  3. #3
    Join Date
    May 2008
    Posts
    5

    Default The problem is the writer is not flushing the data.

    Thankyou Robert.

  4. #4
    Join Date
    May 2008
    Posts
    5

    Default 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();
    }

  5. #5

    Default

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

  6. #6
    Join Date
    May 2008
    Posts
    5

    Default

    Do we have any thread-safe readers ?

  7. #7

    Default

    StagingItemReader in samples is the only example so far.

  8. #8
    Join Date
    May 2008
    Posts
    5

    Default

    Thank you.

Posting Permissions

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