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
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ Spring boot使用的各种示例,以最简单、最实用为标准
1212

1313
- [spring-boot-mybaits-xml](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-mybatis-xml):xml配置版本
1414

15-
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-rabbitmq):spring boot和rabbitmq简单应用
16-
15+
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-rabbitmq):spring boot和rabbitmq各种消息应用案例
1716

17+
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-starter/tree/master/spring-boot-scheduler):spring boot和定时任务案例
1818

1919

2020

2121

2222
文章可以参考这里
2323

24-
- [构建微服务:Spring boot 入门篇](http://www.cnblogs.com/ityouknow/p/5662753.html)
25-
- [构建微服务:Spring boot 提高篇](http://www.ityouknow.com/spring%20boot/2016/02/03/%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1-Spring-boot-%E6%8F%90%E9%AB%98%E7%AF%87.html)
26-
- [构建微服务:Spring Boot中Redis的使用](http://www.ityouknow.com/spring%20boot/2016/03/06/%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1-Spring-Boot%E4%B8%ADRedis%E7%9A%84%E4%BD%BF%E7%94%A8.html)
27-
- [构建微服务:thymeleaf使用详解](http://www.ityouknow.com/thymeleaf/2016/05/01/%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1-thymeleaf%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3.html)
28-
- [构建微服务:spring data jpa的使用](http://www.ityouknow.com/spring%20data%20jpa/2016/08/20/%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1-spring-data-jpa%E7%9A%84%E4%BD%BF%E7%94%A8.html)
29-
- [构建微服务:如何优雅的使用mybatis](http://www.ityouknow.com/mybatis/2016/11/06/%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1-%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E4%BD%BF%E7%94%A8mybatis.html)
24+
- [spring boot(一):入门篇](http://www.cnblogs.com/ityouknow/p/5662753.html)
25+
- [springboot(二):web综合开发](http://www.ityouknow.com/springboot/2016/02/03/springboot(%E4%BA%8C)-web%E7%BB%BC%E5%90%88%E5%BC%80%E5%8F%91.html)
26+
- [springboot(三):Spring boot中Redis的使用](http://www.ityouknow.com/springboot/2016/03/06/springboot(%E4%B8%89)-Spring-Boot%E4%B8%ADRedis%E7%9A%84%E4%BD%BF%E7%94%A8.html)
27+
- [springboot(四):thymeleaf使用详解](http://www.ityouknow.com/thymeleaf/2016/05/01/springboot(%E5%9B%9B)-thymeleaf%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3.html)
28+
- [springboot(五):spring data jpa的使用](http://www.ityouknow.com/springboot/2016/08/20/springboot(%E4%BA%94)-spring-data-jpa%E7%9A%84%E4%BD%BF%E7%94%A8.html)
29+
- [springboot(六):如何优雅的使用mybatis](http://www.ityouknow.com/springboot/2016/11/06/springboot(%E5%85%AD)-%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E4%BD%BF%E7%94%A8mybatis.html)
30+
- [springboot(七):springboot+mybatis多数据源最简解决方案](http://www.ityouknow.com/springboot/2016/11/25/springboot(%E4%B8%83)-springboot+mybatis%E5%A4%9A%E6%95%B0%E6%8D%AE%E6%BA%90%E6%9C%80%E7%AE%80%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88.html)
31+
- [springboot(八):RabbitMQ详解](http://www.ityouknow.com/springboot/2016/11/30/springboot(%E5%85%AB)-RabbitMQ%E8%AF%A6%E8%A7%A3.html)

‎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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.neo;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class ApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
System.out.println("hello world");
15+
}
16+
17+
}

0 commit comments

Comments
 (0)