Results 1 to 9 of 9

Thread: How to stop a job gracefully.

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    19

    Question How to stop a job gracefully.

    Hi

    I have a shell script which is responsible for starting the job.

    This is how I start the job in the "bi.sh"

    java org.springframework.batch.core.launch.support.Comm andLineJobRunner format077-context.xml format077Job batchcycledate=04-JUN-08

    Sometimes this job takes many hours to complete. So we need to stop the job to serve other priorities and then restart it at later time. I want to know is there a graceful way to stop this job ? Do I need to write another shell script for stopping the job?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    With Spring Batch 1.x you have to keep a reference to the JobExecution to stop it gracefully, so the CommandLineJobRunner is not going to help because it either blocks until the job has finished or returns immediately without waiting. You could write your own wrapper or crib from the JMX sample (adhoc-joblauncher-context.xml in the samples project). In 2.0 you will be able to write your second shell script and pass it the JobExecution ID (see work in progress on http://jira.springframework.org/browse/BATCH-773).

  3. #3
    Join Date
    Nov 2006
    Location
    Dallas, TX
    Posts
    15

    Default what if the job runs infinitely?

    I am using the CommandLineJobLauncher and i have a single job(with 2 basic steps).

    When i start the commandline launcher, it takes care of the read and write of the step and repeats them again and again.

    How do i tell through configuration to stop the job after running it only once?

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

    Default

    Even if launching from the command line, you could register the JobExecution with an mBean server, which would then be able to stop the execution.

  5. #5

    Default

    old post ... but as long as you are using a database to persist your executions you should be able to stop them, cant you lucas??

    I am using this code to pull off the status' right now

    BatchStatus status = BatchStatus.UNKNOWN;

    Properties props = new Properties();
    props.put("collectionId", collectionId);

    JobInstance jobInst = jobInstanceDao.getJobInstance(
    getJob(collectionType),
    converter.getJobParameters(props));

    if (jobInst != null) {
    JobExecution jobExecution = jobExecutionDao.getLastJobExecution(jobInst);

    // check if we have a record of this job.
    // if not lets return unkown.
    if (jobExecution != null) {
    status = jobExecution.getStatus();
    }
    }
    So you have accss the execution up there. Of course this is assuming that this is your last job.

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

    Default

    In 1.x, there aren't any checks made while executing to see if updates have been made. In 2.0, the check has been added, along with implementations to do the same thing you just described.

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
  •