Results 1 to 3 of 3

Thread: Stopping a job: delay between 'STOPPING' and 'STOPPED'

Hybrid View

  1. #1

    Default Stopping a job: delay between 'STOPPING' and 'STOPPED'

    The bottom line: I need the job to be stopped quickly (not just the steps), so
    jobLauncher.run(job, jobParameters)
    does not block for so long.

    And now the details:

    I have a simple job set up:
    HTML Code:
    <job id="myJob" restartable="false"
             xmlns="http://www.springframework.org/schema/batch"
            job-repository="dbJobRepository">
            <step id="myStep">
                <tasklet>
                    <chunk reader="myReader"
                           processor="myProcessor"
                           writer="myWriter"
                           commit-interval="100">
                    </chunk>
                </tasklet>
            </step>
        </job>
    I launch the job inside a container:
    Code:
    class AbstractJob{
    
    public Status run(...){
    ...        
    this.jobParameters = jobParamsBuilder.toJobParameters();
    JobExecution jobExecution = jobLauncher.run(job, jobParameters);
    BatchStatus batchStatus = jobExecution.getStatus();
    if (batchStatus == BatchStatus.COMPLETED) ...
    ...
    }
    
    public void abort(){
    ...
    JobOperator jobOperator = KBeansProvider.getBean("jobOperator");
    JobRepository jobRepository = KBeansProvider.getBean("dbJobRepository");
    JobExecution jobExecution = jobRepository.getLastJobExecution(this.jobBeanId, this.jobParameters);
    try {
    jobOperator.stop(jobExecution.getJobId());
    }
    ...
    }
    The launcher.run() method blocks, as I run in synced mode.
    Now, when I abort, I expect the call to return in a reasonable time, as the system is in idle state besides the job.
    The step is indeed stopped, as can be seen in the log:

    Code:
    2012-02-12 18:36:14,649 INFO [org.springframework.batch.core.repository.support.SimpleJobRepository] - <Parent JobExecution is stopped, so passing message on to StepExecution>
    2012-02-12 18:36:14,653 INFO [org.springframework.batch.core.step.ThreadStepInterruptionPolicy] - <Step interrupted through StepExecution>
    2012-02-12 18:36:14,656 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step>
    org.springframework.batch.core.JobInterruptedException: Job interrupted status detected.
    	at org.springframework.batch.core.step.ThreadStepInterruptionPolicy.checkInterrupted(ThreadStepInterruptionPolicy.java:42)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:277)
    The batch_step_execution status is set to stopped in a matter of half a minute or so.
    The problem is, the job itself is "stuck" in'STOPPING' mode.
    Sometimes it gets stopped - but only after an unreasonable time, about 10 minutes, and sometimes it just stays in 'STOPPING' mode.

    I also tried calling stop on the JobExecution itself, but it didn't solve it.

    Thanks
    Last edited by Yuval Rikover; Feb 19th, 2012 at 10:52 AM.

  2. #2
    Join Date
    Feb 2013
    Posts
    1

    Default

    Hello!
    I have a same problem.
    Have you already solved?

  3. #3
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    When asking a job to stop, you are doing just that...asking. There is no guarantee within the framework that processing will end in any particular time frame or at all (depending on your implementation of various artifacts). When the call to stop a job is received, the job is immediately flagged as STOPPING. It is not until all steps processing have stopped (which will check for that flag at different times based on your configuration) that the job is flagged as STOPPED. Without seeing your job configuration, there isn't much insight I can provide into why the gap between those two states is occurring.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

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
  •