Jan 24th, 2008, 07:31 AM
Is it possible to run a particular step from the job on demand
I am new to spring batch. I am using spring batch to run a job that has 10 steps.When i am running the job,it execute all the steps one by one.
But is it possible to run a particular step from the job on demand?
That is i want to call a specific step without running all the 10 steps from a seperate java program.
Jan 24th, 2008, 08:15 AM
You can create a new single-step job and reference the existing step bean definition. I think adhering to the framework's domain model one is supposed to think in terms of 'running a job' rather than 'running a step'.
Jan 24th, 2008, 08:24 AM
That means i can't reuse the same step that i have defined.
I need to add another job. My concern is about the reusability of the step or job.
Jan 24th, 2008, 08:43 AM
Originally Posted by ashok1414
Yes, you need to add another job, but you can reuse the existing step definition. When you define the step as a top-level bean you can reference it from any number of jobs.
I think technically it is not too difficult to create something like 'StepRunner' which would wrap a given step into a job and run it. However I'm not sure whether this should be considered a hack or a valid solution.
Dave or Lucas might have more to say on this topic.
Jan 24th, 2008, 10:46 AM
I really would avoid trying to run Steps directly. The abstraction is really there just to allow for the very common scenario where you do something like load a file into the database, then using that data, do some calculations, and any number of other intermittent steps, then write out the result to a file, or push to a queue, etc. You should still be running jobs. Robert's suggestion was a very good one, you could easily have all of your jobs and your job launcher be loaded up when your server is started using well known constructs (servlet listener). You could then use JMX or even an HTTP request to launch a specific job. There is a work example of this in the samples project.