定时任务轮询比如任务自服务器启动就开始运行,并且每隔5秒执行一次。

以下用spring注解配置定时任务。
1、添加相应的schema

xmlns:task="
xsi:schemaLocation="
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"

  

完整schema如下:

<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、配置自动调度的包和定时开关

<!-- 注解扫描包 -->
<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、添加调度测试类

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定时任务轮询(spring Task)的更多相关文章

  1. 转载《spring定时任务轮询(spring Task)》

    亲测可用 原文网址:http://blog.csdn.net/wanglha/article/details/51026697 本博主注:xmlns:task="http://www.spr ...

  2. 日夕如是寒暑不间,基于Python3+Tornado6+APScheduler/Celery打造并发异步动态定时任务轮询服务

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_220 定时任务的典型落地场景在各行业中都很普遍,比如支付系统中,支付过程中因为网络或者其他因素导致出现掉单.卡单的情况,账单变成了 ...

  3. 【轮询】【ajax】【js】【spring boot】ajax超时请求:前端轮询处理超时请求解决方案 + spring boot服务设置接口超时时间的设置

    场景描述: ajax设置timeout在本机测试有效,但是在生产环境等外网环境无效的问题 1.ajax的timeout属性设置 前端请求超时事件[网络连接不稳定时候,就无效了] var data = ...

  4. Spring Boot+Socket实现与html页面的长连接,客户端给服务器端发消息,服务器给客户端轮询发送消息,附案例源码

    功能介绍 客户端给所有在线用户发送消息 客户端给指定在线用户发送消息 服务器给客户端发送消息(轮询方式) 项目搭建 项目结构图 pom.xml <?xml version="1.0&q ...

  5. 通过Linux定时任务实现定时轮询数据库及发送Http请求

    通过Linux定时任务实现定时轮询数据库及发送Http请求 概述 有时需要临时增加一个定时任务(需要根据数据库查询结果然后发送HTTP请求),如果在项目中额外增加(Java+Spring+Quartz ...

  6. 摆脱Spring 定时任务的@Scheduled cron表达式的困扰

    一.背景 最近因为需要,需要适用Spring的task定时任务进行跑定时任务,以前也接触过,但是因为懒没有好好地理解@Scheduled的cron表达式,这次便对它做了一个全方位的了解和任务,记录下来 ...

  7. spring 定时任务配置

    1.(易)如何在spring中配置定时任务? spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 (程序中一般我们都是到过写的,直观些) 1.定义任务 < ...

  8. spring定时任务

    需求:在tomcat启动时开启一个定时任务,即项目启动完成后,自动执行某一特定任务. 想法:容器启动时执行方法,最容易想到的就是servlet中可以配置load-on-startup,设置一个正整数也 ...

  9. Spring定时任务的几种实现

    近日项目开发中需要执行一些定时任务,比如需要在每天凌晨时候,分析一次前一天的日志信息,借此机会整理了一下定时任务的几种实现方式,由于项目采用spring框架,所以我都将结合 spring框架来介绍. ...

随机推荐

  1. Linux内核分析第五周学习总结:扒开系统调用的三层皮(下)

    韩玉琪 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.给MenuO ...

  2. ceph初步快速部署

    一.基本情况:物理设备:4台惠普dl360,4个千兆网卡 4个1T盘操作系统统一为:CentOS 7.2.1511ceph版本:10.2.3ceph-deploy版本:1.5.36网络情况:192.1 ...

  3. js关闭浏览器的tab页(兼容)

    由于在脚本中使用了 window.close(), 当前非弹出窗口在最新版本的chrome和firefox里总是不能关闭,而在 IE中是可以关闭的 . 在console中弹出提示"Scrip ...

  4. LeetCode OJ-- Wildcard Matching **@

    https://oj.leetcode.com/problems/wildcard-matching/ 模拟通配符的匹配 做法非常好 class Solution { public: bool isM ...

  5. linux下杀死进程(kill)的N种方法

    常规篇: 首先,用ps查看进程,方法如下: $ ps -ef ……smx       1822     1  0 11:38 ?        00:00:49 gnome-terminalsmx   ...

  6. java堆内存与栈内存

    java的内存分为两种,堆内存与栈内存: 堆内存用来存放数组和new的对象,比如一个文件,字节流是存放在堆中,栈内存为这个文件开辟一个索引,也就是这个文件的地址,并且保存在栈中.对象由GC处理释放内存 ...

  7. maven打包时使用的pom配置

    <build> <plugins> <!-- compiler插件, 设定JDK版本 --> <plugin> <groupId>org.a ...

  8. Robot Framework-DatabaseLibrary数据库(MySql)

    Robot Framework-Mac版本安装 Robot Framework-Windows版本安装 Robot Framework-工具简介及入门使用 Robot Framework-Databa ...

  9. Titanium系列--利用Titanium开发android App实战总结

    1. Titanium中,通过ImageView Controller 显示图片,图片地址要放在app/assets下,然后自己建一个文件夹,把图片放在这里.如下图,然后alloy代码:<Ima ...

  10. Lintcode 175 Invert Binary Tree

    I did it in a recursive way. There is another iterative way to do it. I will come back at it later. ...