-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add support for passing objects as job parameters [BATCH-966] #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Dave Syer commented I would prefer to leave this feature to users. The JobParameters are really part of the identity of a job (hence the problem that Robert mentioned with equals()), so making them arbitrary objects just creates more issues than it solves. If your job instance really has an identity, then it should be possible for your launcher client and a StepExecutionListener to share some state (e.g. via a Map) and for the listener to use a key from the JobParameters to populate the step component. I would be more interested in looking at a volatile facet of ExecutionContext - anything you put in there would need to be derived from JobParameters or persistent context of some sort. For your use case in the forum you would still need to organise the shared state, but I don't think that's a problem for you. |
Eddie Mc Greal commented I understand now why using the JobParameters is not such a good idea - and I agree that probably the best transporter of objects into the process is the ExecutionContext.
#1 is probably the easiest and best solution BTW - My ItemReader has a property called inputResourcID which I can set to a constant e.g. "XYZ" in my job xml config file. I can use this later to retrieve the object from the ExecutionContext. This means there is nothing hard coded and I can configure multiple resources or other objects that I may need during execution In general I would think that being able to access objects that are dynamically created outside of the job execution is a necessary feature. My scenario is pretty common - uploading a file to a webserver and then running a batch with uploaded file. |
Eddie Mc Greal commented |
Dave Syer commented I don't think you need to patch anything actually. You can just share a Map between the code that calls the JobLauncher and a StepExecutionListener (as already suggested). If you want to use ThreadLocal that's up to you, but if the map keys are not unique then you have more of a business problem than a technical one. Or am I missing something? |
Eddie Mc Greal commented Sorry Dave but I don't understand how I can " share a Map between the code that calls the JobLauncher and a StepExecutionListener (as already suggested)" The simple job launcher launches a job as follows:
My ItemReader needs to access a Map that I would create before I call taskExecutor.execute - this map can be a member of "MyLauncher" e.g. So again concretely; how do I navigate from |
Dave Syer commented Something like this: <bean class="MyItemReader"> |
Dave Syer commented Nothing to do here, so resolving. |
Eddie Mc Greal opened BATCH-966 and commented
As discussed in http://forum.springframework.org/showthread.php?t=64673
At the moment there is no way of passing objects to the job execution. This would very useful when executing a batch from within e.g. a web application where by a user uploads a file to be processed. There is currently no way of passing this resource to the ItemReader - you have to save it to disk with a static URL so as the ItemReader can pick it up or you can use the dynamic filename mechanism.
In any case I think its something to consider for a future release!
No further details from BATCH-966
The text was updated successfully, but these errors were encountered: