use spring's quartz to create a scheduling:
Quartz has the notion of four entities:a Job, and a JobDetail, a Trigger, a Scheduler.
job:
<bean id="testService" class="test.TestService" >
</bean>
<!--Quartz
jobs are not persisted by default. You need to implement the
StatefulJob interface to have your jobs persisted between executions and between system restarts-->
JobDetail:
<bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" scope="prototype">
<property name="targetObject">
<ref bean="testService" />
</property>
<property name="targetMethod">
<value>oneMethodInTestService</value>
</property>
<property name="concurrent">
<!--enforce that multiple instances of the job will not be executed concurrently-->
<value>false</value>
</property>
</bean>
Trigger:
<bean id="testTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="testJobDetail" />
</property>
<property name="cronExpression">
<!--execution timing -->
<value>0/5 * * * * ?</value>
</property>
</bean>
Scheduler:
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerName" value="timesQuartz" />
<property name="autoStartup" value="true" />
<property name="triggers">
<list>
<ref bean="testTrigger"/>
</list>
</property>
</bean>
分享到:
相关推荐
Exam topics covered include tasks and scheduling, remoting, the Spring Web Services framework, RESTful services with Spring MVC, the Spring JMS module, JMS and JTA transactions with Spring, batch ...
Getting started with Spring Framework is a hands-on guide to begin developing applications using Spring Framework. This book is meant for Java developers with little or no knowledge of Spring ...
Mastering Spring 5 starts with an overview of some of the important Spring Framework features relating to aspect-oriented programming, task scheduling, and scripting with the help of practical ...
* Spring enterprise: Spring Java EE integration, Spring Integration, Spring Batch, jBPM with Spring, Spring Remoting, messaging, transactions, scaling using Terracotta and GridGrain, and more. ...
Learn how to add scheduling to your Spring application with Quartz. Learn how to simplify mail sending with Spring and how to integrate JMS messaging into your application using Spring and ActiveMQ. ...
Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....
2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的...
Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....
这个模块主要由`org.springframework.scheduling`和`org.springframework.task`这两个包组成,它们提供了定时任务的接口和实现。 2. **配置定时任务**: 在Spring中配置定时任务通常有两种方式:XML配置和Java配置...
- **Singleton beans with prototype-bean dependencies**: 单例Bean可以依赖于原型Bean。 - **The other scopes**: 包括`request`、`session`等其他作用域类型。 - **Custom scopes**: 用户可以定义自定义的作用域...
Spring 2.5 对测试框架进行了改进,引入了 @ContextConfiguration 和 @RunWith 注解,方便进行基于注解的测试,支持对 Spring 容器的控制和测试数据源的管理。 十、其他改进 Spring 2.5 还包含了对其他方面的改进,...
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class MyTask { @Scheduled(fixedRate = 5000) public void executeTask()...
Spring-task,也称为Spring的Task Execution and Scheduling模块,提供了一个统一的接口来创建、管理和执行任务。它可以处理一次性任务和周期性任务,支持基于时间(如cron表达式)或间隔时间的调度。 ### 二、注解...
- **Singleton Beans with Prototype-Bean Dependencies**:即使在一个单一实例的Bean中引用了原型模式下的Bean,每次请求时也会创建新的实例。 - **Other Scopes**:除了单一实例和原型模式外,Spring还支持会话...
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @Configuration @EnableScheduling public class TaskSchedulerConfig { @Autowired private EmailService emailService; @Bean ...
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class SpringTaskDemo { // 使用fixedDelay属性,任务在每次执行完后等待...
- Spring 提供了 `org.springframework.scheduling.quartz` 包,使得在 Spring 应用中集成 Quartz 变得简单。 - 通过 `SchedulerFactoryBean`,我们可以方便地配置 Quartz Scheduler,并在 Spring 容器中管理它。 ...
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <!-- 线程池维护线程的最少数量 --> <!-- 允许的空闲时间 --> <!-- 线程池维护线程的最大数量 --> ...
6. **测试支持**:Spring提供了`org.springframework.test`和`org.springframework.mock`包,为单元测试和集成测试提供便利,如`@RunWith(SpringJUnit4ClassRunner.class)`注解。 7. **消息传递**:Spring还支持...