Issue Details (XML | Word | Printable)

Key: BATCH-282
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Dave Syer
Reporter: Douglas C. Kaminsky
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Batch

Make input parameters easier to access from ItemReaders, etc.

Created: 13/Jan/08 04:11 PM   Updated: 05/Sep/08 08:12 AM
Component/s: Core
Affects Version/s: 1.0-m3
Fix Version/s: 2.0.0.M3

Time Tracking:
Issue & Sub-Tasks
Issue Only
Original Estimate: 3.69d
Original Estimate - 3.69d
Remaining Estimate: 2.94d
Time Spent - 0.75d Remaining Estimate - 2.94d
Time Spent: 0.75d
Time Spent - 0.75d Remaining Estimate - 2.94d

Sub-Tasks  All   Open   

 Description  « Hide
Couldn't we add a simpler mechanism for grabbing job identifier info, eg. JobIdentifierAware (or, more user-friendly, InstanceParameterAware) to directly inject all of the relevant parameters directly, without having to deal with the step context.

Source forum thread: http://forum.springframework.org/showthread.php?t=48447

 All   Comments   Work Log   Change History   FishEye   Related Builds      Sort Order: Ascending order - Click to sort in descending order
Lucas Ward added a comment - 14/Jan/08 12:01 AM
I agree, right now getting to the JobIdentifier looks like it would be something like the following:

stepContext.getStepExecution().getJobExecution().getJobInstance().getJobIdentifier().

I'm okay with JobIdentifierAware, I'm not sure if I would go so fine grained as InstancePropertiesAware though.

Lucas Ward added a comment - 24/Jan/08 11:12 AM
Note: JobIdentifier is removed, but JobParameters are the same thing a developer would need access to, so the issue is still there.

Lucas Ward added a comment - 12/May/08 10:32 AM
I moved this to 2.0. I don't think there's anyway we could solve this beyond the convenience method currently in place without making more changes than would be acceptable in a point release.

Douglas C. Kaminsky added a comment - 15/May/08 01:11 PM
What about adding a static class to manage the job parameters for a given execution?

e.g.

JobParametersHolder.getJobParameters()

caveat:
threadsafety is an issue if multiple jobs running in same JVM

probably could handle this with a ThreadLocal?

Dave Syer added a comment - 15/May/08 06:34 PM
ThreadLocal won't work if you launch the job in another thread, or if the reader/writer is accessed in multiple threads (most of the framework implementations do not support this, but it's not that unusual). I can't see how this would work at all in that case, except if you knew the JobExecution id. And if you knew that you would know the job parameters anyway.

Douglas C. Kaminsky added a comment - 16/May/08 11:42 AM
If I understand ThreadLocals properly, the purpose of the ThreadLocal would be to hold a separate immutable copy of the JobParameters for each thread - a lot of threads would have the same exact information, but I'm not sure why you think it wouldn't work as part of a potential strategy. It may take some more components to make it work (e.g. adding some logic that would have each new thread retrieve the job parameters for its corresponding execution from the repository and store it in its thread local via static method call, etc.). The idea of using a static call with a ThreadLocal would just be so all this is handled automatically and stored in memory by the executing class (task executor?) instead of having to go to the repository using the execution id to retrieve your parameters, which it seems is what you're implying by saying "if you knew that you would know the job parameters anyway"

The only other n=1 option I can think of is to make an Aware implementation and create a stock JobExecutionListener that injects this into each Aware artifact (i.e. readers / writers for item oriented, the injected tasklet for tasklet step), but this requires much more configuration to work.

Douglas C. Kaminsky added a comment - 16/May/08 11:44 AM
*having to go to the repository using the execution id

should read

having to go to the repository using the execution id or calling a 5-level deep accessor method