不使用quartz实现定时,使用@Scheduled注解实现定时--一次配置到处使用
来源:互联网 发布:知之一字 众妙之门 编辑:程序博客网 时间:2024/06/06 03:43
在spring中我们可以用task:executor 实现定时执行任务,可以大大的减少像quartz这样的配置,quartz配置很麻烦,首先要配置我们的spring-content.xml 在xmlns 多加下面的语句
xmlns:task="http://www.springframework.org/schema/task"
然后xsi:schemaLocation多加下面的内容:
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
整个约束是:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd" default-lazy-init="true">
在内容中配置:
<task:executor id="executor" pool-size="10"/> <task:scheduler id="scheduler" pool-size="10"/> <task:annotation-driven scheduler="scheduler" executor="executor" proxy-target-class="true"/>
在方法中,添加注解
@Scheduled(cron="0 0 0 * * ? *") //每天0点定时执行 public void test(){ System.out.println("run as ............"); }
ok码完收工
0 0
- 不使用quartz实现定时,使用@Scheduled注解实现定时--一次配置到处使用
- 使用spring @Scheduled注解实现定时任务、
- 使用xml配置Quartz,实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 黑客应用之:net使用方法(1)
- 263. Ugly Number
- WebViewJavascriptBridge-Obj-C和JavaScript互通消息的桥梁
- 【C++】深度探索C++对象模型之类存储
- 开源项目Make Point
- 不使用quartz实现定时,使用@Scheduled注解实现定时--一次配置到处使用
- Nutz中过滤特殊字符
- nginx 或tengine 访问日志分割处理
- ios uiwindow 的用法
- Node Eviction due to OLOGGERD High CPU
- 试题01 A+B和C
- ios 9 隐藏 StatusBar
- 下拉放大headView
- 四道Java基础题 你能对几道?