forked from t-hong/springboot-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTask.java
More file actions
65 lines (52 loc) · 1.77 KB
/
MyTask.java
File metadata and controls
65 lines (52 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.hong.task;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.Date;
/**
* 自定义任务类.
* Created by hong on 2017/6/30.
*/
@Configuration
@EnableScheduling
public class MyTask {
/**
* @Scheduled 详细参数说明:
*
* 1.corn 指定:秒,分钟,小时,日期,月份,星期,年(可选)
* 2.fixedDelay 从上一个任务完成到下一个任务开始的间隔,单位是毫秒
* 3.fixedDelayString 同上,只是字符串类型.
* 4.fixedRate 从上一个任务开始到下一个任务开始的间隔,单位是毫秒
* 5.fixedRateString 同上,只是字符串类型.
* 6.initialDelay 任务第一次执行前需要延迟的毫秒数
* 7.initialDelayString 同上,只是字符串类型.
* 8.zone 指定时区
*
*/
/**
* 这个方法每10秒打印一次.
* 使用cron表达式 指定:秒,分钟,小时,日期,月份,星期,年(可选).
*/
@Scheduled(cron = "0/10 * * * * *")
public void test() {
System.out.println("test......" + new Date().getTime());
}
/**
* 每隔6秒执行.
*/
// @Scheduled(fixedDelay = 6000)
// public void test2() {
// System.out.println("test2..." + new Date().getTime());
// }
// @Scheduled(fixedDelayString = "5000")
// public void test3(){
// System.out.println("test3..."+new Date().getTime());
// }
/**
* 使用外部的cron 表达式.
*/
// @Scheduled(cron = "${my.cron}")
// public void test4() {
// System.out.println("test4..." + new Date().getTime());
// }
}