l转自:http://www.cnblogs.com/linjiqin/p/4530311.html
定时任务轮询比如任务自服务器启动就开始运行,并且每隔5秒执行一次。
以下用spring注解配置定时任务。
1、添加相应的schema
1
2
3
4
|
xmlns:task=" xsi:schemaLocation=" http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
完整schema如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
< beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
</ beans >
|
2、配置自动调度的包和定时开关
1
2
3
4
5
6
|
<!-- 注解扫描包 --> < context:component-scan base-package="com.ljq.web.controller.annotation" />
<!-- Enables the Spring Task @Scheduled programming model --> < task:executor id="executor" pool-size="5" />
< task:scheduler id="scheduler" pool-size="10" />
< task:annotation-driven executor="executor" scheduler="scheduler" />
|
3、添加调度测试类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package com.ljq.web.controller.annotation;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
/** * 调度测试类(每隔5秒执行一次)
*
* @author Administrator
*
*/
@Service public class TaskTest {
@Scheduled (cron = "0/5 * * * * ? " )
public void myTestWork() {
System.out.println(System.currentTimeMillis());
}
} |
备注:cron = "0/5 * * * * ? "从左到右依次是:秒、分、小时、日、月、周、年
相关推荐
主要介绍了Spring定时任务轮询本地数据库实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
asp.net iframe框架跳转以及定时轮询,子页面将新窗口打开到父窗体指定的iframe框架中,以及http_request轮询方法!时间匆忙只简单的写了简单应用。有时间在完善,希望能帮助到需要的朋友!
模拟任务轮询,可用于裸机
在博图环境下用梯形图(LAD)编写一个标准化的,多任务通用的,适应性强的,可移植性强的,Ready for Use的Modbus-RTU主站通讯程序
51单片机循环轮询多任务编程.pdf
一种无OS的MCU实用软件管理系统,包括任务轮询框架,命令管理器、低功耗管理、环形缓冲区等实用模块。系统中广泛利用自定义段技术减少各个模块间的耦合关系,大大提供程序的可维护性。主要功能(支持模块自动化管理...
YDOS-数组方式实现轮询时间片 基于ucosII 的简单任务调度实现 ,有相同任务优先级下的轮询,每个任务优先级可以一样 这种实现方式不是官方的用任务控制空的双向链表实现的 YDOS 嗯,以我的名字命名的,来源于...
裸机多任务轮询定时器,用于简单任务的轮询
13. 引⽤Nacos配置的定时任务失效(Nacos⼯作中遇到问题) 14. Nacos加载那些配置,这些配置的优先级? 15. Nacos配置中⼼宕机了,会影响服务吗? 16. 配置中⼼的技术选型 17. 为什么Feign第⼀次调⽤耗时很⻓? ...
主要介绍了SpringBoot并发定时任务动态定时任务实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
iOS 中效率极高的多 event 定时器,适用于复杂的轮询任务管理!.zip,A simple to use library that gets around a load of problems that arise when you start trying to do much inside 'loop'.
基于轮询的任务调度系统,对于不用freertos的开发来说很适合。可以大大缩短开发周期,代码的结构也清晰
定时轮询?IO频繁且效率太低 想到经常的使用的redis可以设置缓存时间,应该会有过期的事件通知吧,查了一下文档,果然有相关配置,叫做“键空间事件通知”。具体说明可参考官方文档。 技术栈 redis / nodeJs / koa ...
基于STM32设计的任务轮询调度系统功能描述:开启/关闭某任务。不同的任务可以设置不同的间隔运行时间。将某一任务暂停一段时间。粗略统计单个任务上一次的运行花费的时间,在1秒内占用cpu的百分比。粗略统计所有要...
FlowJob任务调度框架,支持延时、定时、corn任务;任务分发支持随机、轮询、一致性哈希、广-flowjob
S7-200SMART_modbus轮询源程序(定时器+计数器方式)-仅需一个MSG指令
Spring Boot&Angular(6)轮询应用程序的实现-全栈应用程序的示例。 演示: 测试凭证: 用户名:“用户”或“管理员” 密码:“密码” 特征: 具有用户/管理员角色系统的JWT身份验证 如何捆绑Angular和Spring ...
+ 开启/关闭某任务。 + 不同的任务可以设置不同的间隔运行时间 + 将某一任务暂停一段时间 + 粗略统计单个任务上一次的运行花费的时间,在1秒内占用cpu的百分比 + 粗略统计所有要运行的任务在某一时刻占用cpu的时间 +...
基于springBoot2.0的springCloud路由网管负载均衡及拦截过滤的简单实现.
这些内核提供单周期乘法、硬件除法、DSP指令集、浮点单元(FPU)等功能,以满足不同应用场景中的计算密集型任务需求。处理器架构遵循哈佛结构,具有独立的指令总线和数据总线,确保高效的代码执行和数据访问。 丰富...