Results 1 to 5 of 5

Thread: Is it possible to run a particular step from the job on demand

  1. #1
    Join Date
    Jan 2008
    Posts
    2

    Default Is it possible to run a particular step from the job on demand

    Hi All,

    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.

    Thanks
    Ashokk

  2. #2

    Default

    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'.

  3. #3
    Join Date
    Jan 2008
    Posts
    2

    Default

    Thanks Robert

    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.

  4. #4

    Default

    Quote Originally Posted by ashok1414 View Post
    Thanks Robert

    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.

    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.

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

    Default

    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.

Posting Permissions

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