alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (schedulingContext-timer.xml)

This example Spring Framework source code file (schedulingContext-timer.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

doctype, job, jobs, lists, registered, registered, scheduledtimertask, scheduledtimertask, schedules, timer, timertasks, utf-8, utf-8, will

The Spring Framework schedulingContext-timer.xml source code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!--
  - Scheduler context for Timer. Schedules "list images" and "check images" tasks.
  - Note that TimerTasks are shared instances, in contrast to throwaway Quartz Jobs.
  -->
<beans>

	<!-- java.util.Timer, with pre-registered scheduled tasks -->
	<!-- Will automatically start scheduling on context startup -->
	<bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
		<property name="scheduledTimerTasks">
			<list>
				<ref local="listImagesScheduledTask"/>
				<ref local="checkImagesScheduledTask"/>
			</list>
		</property>
	</bean>

	<!-- Task definition for ListImagesTimerTask -->
	<!-- Lists the images in the image database and sends a corresponding mail -->
	<bean id="listImagesTimerTask" class="org.springframework.samples.imagedb.scheduling.ListImagesTimerTask">
		<property name="imageDatabase" ref="imageDatabase"/>
		<property name="mailSender" ref="mailSender"/>
		<property name="mailFrom" value="${mail.from}"/>
		<property name="mailTo" value="${mail.to}"/>
	</bean>

	<!-- ScheduledTimerTask for the task defined above -->
	<!-- Registered by the 'timer' bean -->
	<bean id="listImagesScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
		<property name="timerTask" ref="listImagesTimerTask"/>
		<property name="delay" value="10000"/>
		<property name="period" value="10000"/>
	</bean>

	<!-- Job definition that delegates to the specified 'imageDatabase' method -->
	<!-- Convenient way of invoking existing business logic instead of writing a task -->
	<bean id="checkImagesTimerTask" class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
		<property name="targetObject" ref="imageDatabase"/>
		<property name="targetMethod" value="checkImages"/>
	</bean>

	<!-- ScheduledTimerTask for the task defined above -->
	<!-- Registered by the 'timer' bean -->
	<bean id="checkImagesScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
		<property name="timerTask" ref="checkImagesTimerTask"/>
		<property name="delay" value="5000"/>
		<property name="period" value="5000"/>
	</bean>

</beans>

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework schedulingContext-timer.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.