Results 1 to 4 of 4

Thread: Restart of a step

  1. #1
    Join Date
    Jun 2008
    Posts
    21

    Default Restart of a step

    Hi

    the following is my job configuration:

    Code:
    	<bean id="demoJob" class="...SimpleJob">
    		<property name="name" value="demoJob" />
    		<property name="steps">
    			<list>
    				<ref bean="taskletDemoStep" />
    			</list>
    		</property>
    	</bean>
    
    	<bean id="taskletDemoStep" parent="taskletStep">
    		<property name="startLimit" value="2" />
    		<property name="tasklet" ref="tasklet" />
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="transactionManager" ref="batchExecTransactionManager"></property>
    	</bean>
    
    	<bean id="tasklet" class="batch.demo.MyTasklet" />
    The tasklet always throws an Exception.

    I am using quartz to trigger this job once. Once triggered, I am expecting this job to run 2/3 times and fail with StartLimitExceededException. However, it does not restart on itself.

    Any wrong with the above configuration?

    Thanks for your help.

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    Spring Batch doesn't trigger jobs to restart automatically. You need to configure Quartz to relaunch it. (Or, you could write a custom JobLauncher that does it if you want).

  3. #3
    Join Date
    Jun 2008
    Posts
    21

    Default

    Ok. If we were to relaunch a job, what class should the joblauncher really use?

    I thought of using JobOperator, but that would mean cyclic dependencies, as JobOperator already holds a reference to JobLauncher. To me, cyclic dependencies dont look good.

    What are your suggestions?

  4. #4
    Join Date
    Feb 2008
    Posts
    488

    Default

    I'm confused by your question. I was just thinking you could create something like this and use it as your JobLauncher instead of using the SimpleJobLauncher directly:

    Code:
    public class RelaunchingJobLauncher implements JobLauncher {
        private JobLauncher simpleJobLauncher;
    
        public JobExecution run(Job job, JobParameters jobParameters) {
            JobExecution jobExecution;
            do {
                jobExecution = simpleJobLauncher.run(job, jobParameters);
            } while(jobExecution.getStatus() == BatchStatus.FAILED)
    
            return jobExecution;
        }
    }

Posting Permissions

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