Results 1 to 3 of 3

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

Threaded 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.

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
  •