add scheduler · javamickey/spring-boot-examples@cd05402 · GitHub
Skip to content

Commit cd05402

Browse files
committed
add scheduler
1 parent a4105ec commit cd05402

7 files changed

Lines changed: 144 additions & 8 deletions

File tree

README.md

Lines changed: 10 additions & 8 deletions

spring-boot-scheduler/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.neo</groupId>
7+
<artifactId>spring-boot-scheduler</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-scheduler</name>
12+
<description>Demo project for Spring Boot and scheduler</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.4.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-devtools</artifactId>
39+
<optional>true</optional>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
<configuration>
49+
<fork>true</fork>
50+
</configuration>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
55+
56+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.neo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
6+
7+
@SpringBootApplication
8+
@EnableScheduling
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.neo.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+
/**
10+
* Created by summer on 2016/12/1.
11+
*/
12+
13+
@Component
14+
public class Scheduler2Task {
15+
16+
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
17+
18+
@Scheduled(fixedRate = 6000)
19+
public void reportCurrentTime() {
20+
System.out.println("现在时间:" + dateFormat.format(new Date()));
21+
}
22+
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.neo.task;
2+
3+
import org.springframework.scheduling.annotation.Scheduled;
4+
import org.springframework.stereotype.Component;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* Created by summer on 2016/12/1.
10+
*/
11+
12+
@Component
13+
public class SchedulerTask {
14+
15+
private int count=0;
16+
17+
@Scheduled(cron="*/6 * * * * ?")
18+
private void process(){
19+
System.out.println("this is scheduler task runing "+(count++));
20+
}
21+
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.application.name=spirng-boot-scheduler
2+
Lines changed: 17 additions & 0 deletions

0 commit comments

Comments
 (0)