Results 1 to 10 of 10

Thread: How to launch or re-launch a job by hitting the database tables.

  1. #1
    Join Date
    May 2011
    Posts
    6

    Smile How to launch or re-launch a job by hitting the database tables.

    Hi

    I need some help figuring out if its posible to launch a job by simply creating a new tuple in the Batch_Job_Execution table, or something like that. I think it is, if true, do you know how could I do that... or maybe into which class from the batch-admin I should look into.

    I'm evaluating this technology and I want to know if I can easilly integrate it to our existing management web platform, so I dont really want to use spring-batch-admin module but some kind of custom classes.

    Thank you in advance.

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    you should use the SimpleJobLauncher that hits the database using the JobRepository and launches the job accordingly. You don't need Spring Batch Admin to launch a job, the Java API is enough.

  3. #3
    Join Date
    May 2011
    Posts
    6

    Default

    Well that won't actually work, I need the web app to be separate from the batch process. So I will not be running the Jobs at the same VM.

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    forget about the web app: use the SimpleJobLauncher to launch the job in the batch process. There must be a JVM process somewhere that executes the Spring Batch job, and this process will actually use the Spring Batch's launching API to start the job. How this JVM process is spawned is up to you, it can be from the command line, using cron.

  5. #5
    Join Date
    May 2011
    Posts
    6

    Default

    Arno, first thank you for your help.

    Ok, so what you are saying is that I can launch from a different VM instance in a total different box by hitting the database through the SimpleJobLauncher?

    Can I also stop a running Job? How could I configure the SimpleJobLauncher to do this without hatching a local Job?

  6. #6
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    Ok, so what you are saying is that I can launch from a different VM instance in a total different box by hitting the database through the SimpleJobLauncher?
    yes. As soon as Spring Batch Admin and the job launcher are using the same database, you're fine. Spring Batch Admin would only display the batch metadata.

    Can I also stop a running Job? How could I configure the SimpleJobLauncher to do this without hatching a local Job?
    There's nothing to do with the SimpleJobLauncher for this. You can use Spring Batch Admin or the JobExplorer (a Spring bean you configure). They both set the job execution's status to STOPPED (updating then the database). The running step is then in charge of checking the status and stop the execution (which happens at chunk boundaries for a chunk-oriented step).

  7. #7
    Join Date
    May 2011
    Posts
    6

    Default

    Arno, this sounds great.

    One more question, I read that Spring Batch depends a 3rd party scheduling framework (like Quartz) for hatching the jobs. Will my database entries prevent the scheduled executions? Or this only applies to "runtime" jobs?

  8. #8
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    I read that Spring Batch depends a 3rd party scheduling framework (like Quartz) for hatching the jobs.
    yes, Spring Batch only provides a Java API to launch jobs, scheduling should come from a third-party (Quartz, Spring) lib or system (cron).

    Will my database entries prevent the scheduled executions? Or this only applies to "runtime" jobs?
    I'm not sure I get your question. A Java-based scheduler like Quartz needs to use the JobLauncher too, so scheduled executions don't interfere with other executions.

  9. #9
    Join Date
    May 2011
    Posts
    6

    Default

    Well,

    Lets say that we want to halt all the executions from a particular JobExecution instance for a DB maintenance.
    Now I know that I can actually stop the Jobs that are in the running state through the SJL. But what about the jobs that are not being executed at that very time.

    Quartz might try to execute those, can the SJL from Batch change the scheduling from Quartz? What will happen if Quartz try to execute a job that I have stopped.

  10. #10
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    Now I know that I can actually stop the Jobs that are in the running state through the SJL.
    you can't stop a job with the JobLauncher, you must use the JobOperator.

    Quartz might try to execute those, can the SJL from Batch change the scheduling from Quartz? What will happen if Quartz try to execute a job that I have stopped.
    Indeed, if you don't stop Quartz, it can still launch jobs. But you can activate a maintenance flag somewhere (in the database?) that the scheduled Quartz's jobs check before launching the Spring Batch's jobs (Quartz's jobs are scheduled operations, Spring Batch's jobs handle bulk processing, the name of the interfaces is the same, don't confuse!). This is up to you to write the Quartz's job code accordingly, Spring Batch cannot do anything for you in this case.

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
  •