Results 1 to 4 of 4

Thread: Singletons or prototypes

  1. #1
    Join Date
    Dec 2006
    Posts
    108

    Default Singletons or prototypes

    Hi All,

    Just a very stupid simple question.....

    Are all steps and tasklets prototypes by default ?

    Thanks...Vijay

  2. #2

    Default

    no, they are just ordinary spring beans => singletons by default

  3. #3

    Default

    I have asked similar question before and here is what I understood, wish it can help:

    Normally, tasklet is singleton by default. Therefore, if the tasklet's logic is stateless, it will run well.

    However, if you want to have a stateful, or want to be StepContextAware, you may make the scope of the tasklet being "step" (you should register the scope first, refer to the unit test), and put <aop:scoped-proxy/> in the tasklet's bean config in app context. It should make your tasklet instantiated for every new step.

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    For a little bit of background around the issue:

    When using steps, lots of very stateful resources are generally created. For example, if reading from the database you may open a cursor that stays open for the life of the batch job. This should be closed as soon as the step finishes, which is why we have step scope, to ensure resources are free. So, in theory, you could make your steps 'prototype scoped', but that doesn't necessarily guarantee that the resources created will be released without using something like step scope or closing the application context.

    As a side note, there's an issue to move the responsibilities of step scope to the step itself, but the overall effect is the same:

    http://jira.springframework.org/browse/BATCH-364

Posting Permissions

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