Announcement Announcement Module
Collapse
No announcement yet.
Is it possible to run a particular step from the job on demand Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment

          Working...
          X