Announcement Announcement Module
Collapse
No announcement yet.
synchronisation of tasks/jobs how to Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • synchronisation of tasks/jobs how to

    I am new to spring batch and quartz but have a few examples working well but I cant see how to proceed more generally with the whole set of requirements. I think I might be missing the interplay between Quartz Triggers and Spring Batch.

    Requirements -:
    I have a set of tasks to run sequentially every night.
    I also have a polling task that needs to run every minute or so.
    These must not run in parallel.

    The question is how do I achieve this? I tried two separate quartz triggers but I cant see how to ensure only one runs at a time. Of course the answer might be to synchronise elsewhere.

    Regards

  • #2
    In Spring Batch, the jobLauncher in default is using synchronized taskExecutor, which means the jobs you run with this launcher will run in sequential.

    Comment


    • #3
      Originally posted by Benny Jiang View Post
      In Spring Batch, the jobLauncher in default is using synchronized taskExecutor, which means the jobs you run with this launcher will run in sequential.
      Hi thanks. This is what I thought would happen, but in testing I fire up to 10 jobs (I believe this is the thread limit).

      Code:
      <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      		<property name="triggers">
      			<list>
      				<bean id="repeat" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
      					<property name="jobDetail" ref="repeatDetail" />
      					<property name="startDelay" value="5001" />
      					<property name="repeatInterval" value="100"/>
      				</bean>
      			</list>
      		</property>
      	</bean>
      
      
      <bean id="minuteRepeatDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
      		<property name="jobClass" value="foo.JobLauncherDetails" />
      		<property name="group" value="repeat" />
      		<property name="jobDataAsMap">
      			<map>
      				<entry key="jobName" value="minuteRepeatJob"/>
      				<entry key="jobLocator" value-ref="jobRegistry"/>
      				<entry key="jobLauncher" value-ref="jobLauncher"/>
      			</map>
      		</property>
      	</bean>
      	
      	<batch:job id="minuteRepeatJob" restartable="true" incrementer="runIdIncrementer">
      		<batch:step id="harvestSchedule" next="explodeXMLRecords">
      			<batch:tasklet ref="harvestScheduler" />
      		</batch:step>
      		<batch:step id="explodeXMLRecords">
      			<batch:tasklet>
      				<batch:chunk reader="xmlExploderItemReader" processor="xmlExploderItemProcessor" writer="xmlExploderItemWriter" commit-interval="1000" />
      			</batch:tasklet>
      		</batch:step>
      	</batch:job>
      
      <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
      		<property name="jobRepository" ref="jobRepository" />
      		<property name="taskExecutor">
      			<bean class="org.springframework.core.task.SyncTaskExecutor" />
      		</property>
      	</bean>
      10:45:28,718 [INFO ] org.springframework.batch.core.launch.support.Simp leJobLauncher [run():118] - Job: [FlowJob: [name=minuteRepeatJob]] launched with the following parameters: [{run.id=1281087928093}]
      10:45:28,718 [INFO ] org.springframework.batch.core.launch.support.Simp leJobLauncher [run():118] - Job: [FlowJob: [name=minuteRepeatJob]] launched with the following parameters: [{run.id=1281087927343}]
      10:45:28,765 [INFO ] org.springframework.batch.core.launch.support.Simp leJobLauncher [run():118] - Job: [FlowJob: [name=minuteRepeatJob]] launched with the following parameters: [{run.id=1281087928687}]

      Is this maybe something to do with the incrementor I am using or is the fact I trigger using quartz the culprit?

      Comment


      • #4
        Originally posted by Benny Jiang View Post
        In Spring Batch, the jobLauncher in default is using synchronized taskExecutor, which means the jobs you run with this launcher will run in sequential.
        Ah it seems quartz uses a threaded pool as a default. Adding this fixed my problems. I guess it is a bit unfair to expect jobs to be called synchronously despite several calling threads. Thanks.

        Code:
        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="taskExecutor">
        <bean class="org.springframework.core.task.SyncTaskExecutor" />
        </property>
        </bean>

        Comment

        Working...
        X