Results 1 to 4 of 4

Thread: scheduled batch runs more than once

  1. #1
    Join Date
    Apr 2010
    Posts
    11

    Default scheduled batch runs more than once

    Hi,

    I'm using a SimpleJobLauncher with SimpleAsyncTaskExecutor to run a batch with a daily cron. The cron runs at the proper time, but it runs like 60 times in a row for some odd reason. I've invoked the jobLauncher manually and insured that my code doesn't actually run the batch 60 times. Any ideas what it could be? My config is below:

    Code:
    <beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher" >  
    		<beans:property name="jobRepository" ref="jobRepository"/>
    		<beans:property name="taskExecutor">
    			<beans:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    		</beans:property>
    
    <beans:bean id="exportUserListTasklet" class="com.foo.batch.jobs.userlist.ExportUserList" />
    		<batch:job id="exportUserListJob" job-repository="jobRepository">
    			<batch:step id="exportUserListJobStep0">
    				<batch:tasklet ref="exportUserListTasklet" transaction-manager="jobRepository-transactionManager" />
    			</batch:step>
    		</batch:job>	
    
    <task:annotation-driven executor="taskExecutor" />
    	<task:executor id="taskExecutor" pool-size="5-25" queue-capacity="100" rejection-policy="DISCARD" />
    	<task:scheduler id="taskScheduler" pool-size="10"/>
    	
    		<!-- TASKS -->
    		<beans:bean id="exportUserListTask" class="com.foo.tasks.ExportUserListTask">
    			<beans:property name="buildEnvironment" value="${BUILD_ENVIRONMENT}" />
    		</beans:bean>
    		</beans:bean>
    	
    	<task:scheduled-tasks scheduler="taskScheduler">
    		<task:scheduled ref="exportUserListTask" method="run" cron="* 1 21 * * *" />
    	</task:scheduled-tasks>
    Thank you in advance!

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    the cron expression triggers the launch every second (between 21:01 and 21:02, every day). Is it what you want?

  3. #3
    Join Date
    Apr 2010
    Posts
    11

    Default

    arno,

    No, I'd just like it to execute at 21:01 every day. Is the cron expression similar to the system cron flags?

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    No, I'd just like it to execute at 21:01 every day.
    ok, so your cron expression should be 0 1 21 * * * instead of * 1 21 * * *. This one should also work: 0 1 21 * * ? (you don't specify the day twice, but it doesn't matter in this case).

    Is the cron expression similar to the system cron flags?
    cron expressions in Spring (and Quartz) use the same syntax as the system cron's ones (e.g. *, ?, 0/*, etc.), except there's an additional field for seconds (on the left). The last field (on the right) is for years, but it's optional.

Posting Permissions

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