Results 1 to 5 of 5

Thread: How to Repeat Job based on parameters

  1. #1
    Join Date
    Feb 2009
    Location
    India
    Posts
    2

    Default How to Repeat Job based on parameters

    I want to execute my job more than once based on the input parameters. Users will pass month as Job Parameter. If they pass Jan as a month, I should repeat my job from Jan to current month as separate execution. If they are not passing Month Parameter then I should Query the database to get the last execution of this job to find the month and then repeat the same job till current month by passing month as argument to my Job.

    Please help my how to do this with Spring Batch.

    Thanks
    Hari

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    Wrap the JobLauncher. Your version will query the database, figure out what months need to run, create JobParameters, and pass them to the delegate JobLauncher to run the specific instance of the job.

    The way the framework is designed, you will not be able to use the exact same parameters if the previous execution was COMPLETED. To circumvent this, you can add an additional parameter, the current timestamp, that will ensure that the JobParameters are unique.

  3. #3
    Join Date
    Feb 2009
    Location
    India
    Posts
    2

    Default

    Thanks for Quick response DHGarrette.

    If I already have few JobParameters in the JobParameters object of JobLauncher Run() method, How can I add new JobParameter at run time. I did not find any method to add new JobParameter to the existing JobParameters object.

    I am trying to convert the given JobParameters object into Properties using DefaultJobParametersConverter and then adding new value to the Properties object and then converting it back to JobParameters object. Is it the right approach. Please let me know.

  4. #4
    Join Date
    Feb 2008
    Posts
    488

    Default

    Take a look at the JobParametersBuilder. It should make things easier.

  5. #5
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    Also look at the JobParametersIncrementer and JobOperator interfaces (notably startNextInstance()).

Tags for this Thread

Posting Permissions

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