Announcement Announcement Module
No announcement yet.
MultiResourceItemWriter and restartability Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MultiResourceItemWriter and restartability


    I have noticed an issue with restartability when using the MultiResourceItemWriter. I'm not sure if this writer is supposed to be able to support restartability but I assumed it was.

    The problem I'm seeing is that if the batch job fails after having written records out to one or more of the output files, on restart the reader starts from the position of the failure, however the MultiResourceItemWriter starts writing at the beginning of the file again.

    I spotted a potential issue in the code and was wondering if someone can verify if this is a problem or not. In the open() method of MultiResourceItemWriter, the following code attempts to open an existing file on restart:

    if (executionContext.containsKey(getKey(CURRENT_RESOU RCE_ITEM_COUNT))) {
    // It's a restart;
    else {
    opened = false;

    The 'opened' flag does not get set to true for the restart. In the write() method we then have the following:

    if (!opened) {
    File file = setResourceToDelegate();
    // create only if write is called
    Assert.state(file.canWrite(), "Output resource " + file.getAbsolutePath() + " must be writable"); ExecutionContext());
    opened = true;

    which results in the delegate(a StaxEventItemWriter) opening the file with an empty execution context - therefore it opens the file for writing at position 0.

    Can anyone verify this is a problem, or am I not configuring the writers properly in some way?


  • #2
    Can anyone shed any light on this?