springtask 基本使用和 cron 表达式
springtask 的基本使用和 cron 表达式
spring 容器依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
开启任务注解驱动。即扫描的时候扫描 springtask 相关的注解。
<?xml version="1.0" encoding="UTF-8"?>
<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:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.2.xsd
">
<context:component-scan base-package="com.mozq.task"/>
<task:annotation-driven/>
</beans>
准备 Spring 容器 + 定时任务
为了使用 springtask 需要准备 spring 容器和定时任务。通过 main 方法创建 spring 容器。@Scheduled 注解创建定时任务。
package com.mozq.task;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TaskDemo {
@Scheduled(cron="* * * * * ?")
public void sendOrderMessage(){
System.out.println("发送订单消息");
}
public static void main(String[] args) throws InterruptedException {
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("spring-task.xml");
Thread.sleep(1000);
}
}
参考文档
springtask 基本使用和 cron 表达式的更多相关文章
- cron表达式的双重人格:星期和数字到底如何对应?
写在前面 cron在希腊语中是时间的意思,而cron表达式(cron expression)则是遵循特定规则,用于描述定时设置的字符串,常用于执行定时任务.本文总结了不同环境(如平台.库等)下,cro ...
- quartz.net 时间表达式----- Cron表达式详解
序言 Cron表达式:就是用简单的xxoo符号按照一定的规则,就能把各种时间维度表达的淋漓尽致,无所不在其中,然后在用来做任务调度(定时服务)的quart.net中所认知执行,可想而知这是多么的天衣无 ...
- 摆脱Spring 定时任务的@Scheduled cron表达式的困扰
一.背景 最近因为需要,需要适用Spring的task定时任务进行跑定时任务,以前也接触过,但是因为懒没有好好地理解@Scheduled的cron表达式,这次便对它做了一个全方位的了解和任务,记录下来 ...
- QuartZ Cron表达式
Cron Expressions cron的表达式是字符串,实际上是由七子表达式,描述个别细节的时间表. Seconds Minutes Hours ...
- cron表达式
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...
- cron表达式详解[转]
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...
- Quartz.net配置文件实例及cron表达式详解
从XML文件创建作业 最新版本的quartz.net支持直接从xml文件创建作业,使用起来很方便.配置文件的格式可以参考下面的例子 <?xml version="1.0" e ...
- 初识Quartz(入门案例)+常用的Cron表达式
1.Quartz架构图 1.实体层 package cn.happy.entity; //1. public class Plan { //时间 private String date; //任务 p ...
- Quartz Cron表达式 在线生成器
Cron Expressions——Cron 表达式 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天(星期)(1~ ...
随机推荐
- 算法(贪心|BF|KMP)
贪心算法 前置知识 const Greedy = num => { //贪心 let arr = [100, 20, 10, 5, 2, 1] let count = 0; for (let i ...
- javascript 对象,函数,原型和 this
1.对象 在javascript里,一切都是对象,包括函数自身(不是指具体的函数,而是指"Function"这个东东).例如: var fun1=new Function(&quo ...
- CentOS7 安装nginx-1.14.0
nginx源码包:http://nginx.org/en/download.html 1.安装gcc gcc是用来编译下载下来的nginx源码 yum install gcc-c++ 2.安装pcre ...
- JS中Map的用法
声明 var map = new Map(); 设值 map.set("key","value"); 取值 map.get("key"); ...
- Java中List集合去除重复数据的六种方法
1. 循环list中的所有元素然后删除重复 public static List removeDuplicate(List list) { for ( int i = 0 ; i < list. ...
- JSONBuilder的用法
一.JSONBuilder可以向文件中写入写入json字符串.如下面的例子: 1 public class Test 2 { 3 public static void main(String args ...
- 《 .NET并发编程实战》阅读指南 - 第11章
先发表生成URL以印在书里面.等书籍正式出版销售后会公开内容.
- HTML模版大全网
HTML模版大全网,里面有一部分是后台管理的网站模版,HTML全都有.大家有需要的话,可以自行去下载. http://www.htmlmbdq.com
- mini QQ(项目一)
一个多人聊天工具(C/S结构),实现了如下功能: 一个可视化窗口,支持鼠标点击事件 注册功能,用户可以注册自己的聊天账号, 注册信息包括: 账号名(可以用姓名来替代账号,支持中文), 密码(聊天框输入 ...
- webapi ClaimsPrincipal使用
参考文档:ClaimsPrincipal Class 个人demo:SwaggerDemoApi 今天看到一段代码懵逼了 var principal = new ClaimsPrincipal(new ...