-
Feb 14th, 2008, 11:11 PM
#1
Singletons or prototypes
Hi All,
Just a very stupid simple question.....
Are all steps and tasklets prototypes by default ?
Thanks...Vijay
-
Feb 18th, 2008, 03:09 AM
#2
no, they are just ordinary spring beans => singletons by default
-
Feb 18th, 2008, 04:07 AM
#3
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.
-
Feb 18th, 2008, 11:25 AM
#4
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
-
Forum Rules