Results 1 to 5 of 5

Thread: In-memory repository and ExecutionContext

  1. #1
    Join Date
    Apr 2008
    Posts
    14

    Default In-memory repository and ExecutionContext

    Hello,

    We are trying to pass some simple parameters from one Job to another. Code looks like this:
    ctx.putLong(CLAIM_ID, currentClaim.getId());
    System.out.println("Claim id in exn ctx "+se.getExecutionContext().getLong(CLAIM_ID));
    se.setExecutionContext(ctx);

    In the following step we access the ExecutionContext like this:
    ExecutionContext cxt = se.getExecutionContext();
    System.out.println("Claim id: "+ cxt.getLong(CLAIM_ID));

    Resulting in this error:
    INFO: Job: [SimpleJob: [name=simpleJob]] failed with the following parameters: [{}{timeOfKickoff=1208842406699}{}{}]
    java.lang.ClassCastException: Value for key=[claimId] is not of type: [class java.lang.Long], it is [null]

    We are using an In-Memory Job Repository and, as you can tell from the exception, a SimpleJob.
    Does and ExecutionContext not get passed between steps when using an in-memory repo?
    Any clues appreciated.

    Thanks, Sjoerd

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    An ExecutionContext is scoped to the step, so it doesn't get passed between steps (independent of the repository implementation). To use it like this to pass information between steps you need to write a StepExecutionListener that listens to both steps and has instance variables that are used to transfer data between one step and the next.

  3. #3
    Join Date
    Apr 2008
    Posts
    14

    Default

    Hi Dave,

    Thanks for the fast reply. You state that an ExecutionContext is scoped to a Step. However, the Spring Batch reference guide states:
    "An ExecutionContext represents a collection of key/value pairs that are persisted and controlled by the framework in order to allow developers a place to store persistent state that is scoped to a JobInstance."

    Is there any other mechanism offered by Spring Batch for passing data between different steps in a job?

    Thanks again,
    - Sjoerd

  4. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Sorry, the user guide is wrong (I have changed it for the next release). So...

    you need to write a StepExecutionListener that listens to both steps and has instance variables that are used to transfer data between one step and the next.
    This is sort of a workaround for 1.0. You might find something scoped at the JobExecution level in future versions (there are a couple of JIRAs already: http://jira.springframework.org/browse/BATCH-264, http://jira.springframework.org/browse/BATCH-505).

  5. #5
    Join Date
    Apr 2008
    Posts
    14

    Default

    The JIRA's describe our use case exactly.
    For now we have created our own container that we inject into the steps.

Posting Permissions

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