Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de9385c

Browse files
committed
完成定时任务
1 parent 15b0d2e commit de9385c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

‎springboot-schedu/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<artifactId>spring-boot-starter-test</artifactId>
3636
<scope>test</scope>
3737
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-devtools</artifactId>
42+
<optional>true</optional>
43+
</dependency>
3844
</dependencies>
3945

4046
<build>

‎springboot-schedu/src/main/java/com/ithobart/schedu/ScheduApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
56

7+
@EnableScheduling
68
@SpringBootApplication
79
public class ScheduApplication {
810

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ithobart.schedu.task;
2+
3+
import org.springframework.scheduling.annotation.Scheduled;
4+
import org.springframework.stereotype.Component;
5+
6+
import java.text.SimpleDateFormat;
7+
import java.util.Date;
8+
9+
@Component
10+
public class SchedulerTask {
11+
12+
private int count=0;
13+
14+
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
15+
16+
@Scheduled(cron="*/5 * * * * ?")
17+
private void process(){
18+
System.out.println("this is scheduler task runing "+(count++));
19+
}
20+
21+
@Scheduled(fixedRate = 5000)
22+
public void reportCurrentTime() {
23+
System.out.println("现在时间:" + dateFormat.format(new Date()));
24+
}
25+
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /