Announcement Announcement Module
Collapse
No announcement yet.
Job restartable attribute not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Job restartable attribute not working

    I have a batch job I want to run every minute. The scheduler launches the job every minute as planned, but after the first launch, the same job instance is being used. There is a flag in my ItemReader that gets tripped once the code executes once, so with the same instance being used with every subsequent launch, nothing new gets read after that first run.

    I looked into the docs (http://static.springsource.org/sprin...reJob.html)and it said set the restartable attribute to false for the job bean. This should force a new instance to be created with every call (Section 4.1.1 Restartability).

    This has not fixed the issue. If I write out "this.hashCode()" I get the same hash ID each time the reader class is called.

    I tried putting the restartable attribute on the job, as well as its parent (which is an extension of SimpleJob), and both did not help.

    I also have a timestamp appended in the jobParameters for the job launcher, so each job has unique parameters. This still does not fix it either. The job name is always the same.

    Is there something I am missing?

    Code:
    <bean id="simpleJob" class="CustomJob" abstract="true">
          <property name="jobRepository" ref="jobRepository"/>
          <property name="restartable" value="false"/>
     </bean>
    
    <bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean" abstract="true">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="jobRepository" ref="jobRepository"/>
        <property name="startLimit" value="100"/>
        <property name="commitInterval" value="1"/>
    </bean>
    
    <batch:job id="myJob" parent="simpleJob">
            <batch:step id="Step1" next="step2" parent="simpleStep">
                <batch:tasklet>
                    <batch:chunk>
                        <batch:reader>
                            <bean class="myReader">
                                <property name="userName" value="***"/>
                                <property name="password" value="***"/>
                                <property name="url" value="***"/>
                            </bean>
                        </batch:reader>
                        <batch:writer>
                            <bean class="MyWriter">
                                <property name="dataSource" ref="dataSource"/>
                                <property name="updateOnKeyConflict" value="false"/>
                                <property name="table" value="myTable"/>
                            </bean>
                        </batch:writer>
                    </batch:chunk>
                </batch:tasklet>
            </batch:step>
            <batch:step id="step2" next="step3" parent="simpleStep">
                <batch:tasklet>
                    <bean class="queryTasklet">
                        <property name="dataSource" ref="dataSource"/>
                        <property name="sql" value="***"/>
                    </bean>
                </batch:tasklet>
            </batch:step>
            <batch:step id="step3" parent="simpleStep">
                <batch:tasklet>
                    <batch:chunk>
                        <batch:reader>
                            <bean class="mySeriesReader">
                                <property name="userName" value="***"/>
                                <property name="password" value="***"/>
                                <property name="url" value="***"/>
                            </bean>
                        </batch:reader>
                        <batch:writer>
                            <bean class="mySeriesWriter">
                                <property name="timeSeriesDAO" ref="timeSeriesDAO"/>
                                <property name="updateOnKeyConflict" value="false"/>
                            </bean>
                        </batch:writer>
                    </batch:chunk>
                </batch:tasklet>
            </batch:step>
        </batch:job>

  • #2
    The job is still a singleton as are the step restartable means that a job execution cannot be restarted. It is not about the Job .

    Also you shouldn't be switching things in your reader, you probably want/need them to be dependent on your execution, so you might want to store them in the execution and use late binding (explained in chapter 5).

    Comment


    • #3
      Thank you Marten, adding the scope="step" attribute to the reader class corrected the issue I was having.

      Comment

      Working...
      X