添加代码示例springboot-schedule

This commit is contained in:
yidao620
2018-02-27 19:28:19 +08:00
parent e7f352ade5
commit 465ad8d2c4
11 changed files with 350 additions and 1 deletions

View File

@ -0,0 +1,12 @@
package com.xncoding.pos;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,31 @@
package com.xncoding.pos.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* ScheduleConfig
*
* @author XiongNeng
* @version 1.0
* @since 2017/9/13
*/
@Configuration
@EnableScheduling
public class ScheduleConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(destroyMethod="shutdown")
public ExecutorService taskExecutor() {
return Executors.newScheduledThreadPool(5);
}
}

View File

@ -0,0 +1,46 @@
package com.xncoding.pos.jobs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 定时任务
*
* 第一位表示秒取值0-59
* 第二位表示分取值0-59
* 第三位表示小时取值0-23
* 第四位,日期天/日取值1-31
* 第五位日期月份取值1-12
* 第六位星期取值1-71表示星期天2表示星期一
* 第七位年份可以留空取值1970-2099
*
* @author XiongNeng
* @version 1.0
* @since 2017/9/27
*/
@Component
public class HeartbeatJob {
private static final Logger logger = LoggerFactory.getLogger(HeartbeatJob.class);
/**
* 检查状态1
*/
@Scheduled(cron = "0 26 19 * * ?")
public void checkState1() {
logger.info(">>>>> cron中午12:30上传检查开始....");
logger.info(">>>>> cron中午12:30上传检查完成....");
}
/**
* 检查状态2
*/
@Scheduled(cron = "0 05 18 * * ?")
public void checkState2() {
logger.info(">>>>> cron晚上18:00上传检查开始....");
logger.info(">>>>> cron晚上18:00上传检查完成....");
}
}

View File

@ -0,0 +1,39 @@
##########################################################
################## 所有profile共有的配置 #################
##########################################################
################### spring配置 ###################
spring:
profiles:
active: dev
---
#####################################################################
######################## 开发环境profile ##########################
#####################################################################
spring:
profiles: dev
logging:
level:
ROOT: INFO
com:
xncoding: DEBUG
file: E:/logs/app.log
---
#####################################################################
######################## 测试环境profile ##########################
#####################################################################
spring:
profiles: test
logging:
level:
ROOT: INFO
com:
xncoding: DEBUG
file: /var/logs/app.log

View File

@ -0,0 +1,23 @@
_____ _______ _____ _____
/\ \ /::\ \ /\ \ /\ \
/::\____\ /::::\ \ /::\____\ /::\ \
/:::/ / /::::::\ \ /:::/ / /::::\ \
/:::/ / /::::::::\ \ /:::/ / /::::::\ \
/:::/ / /:::/~~\:::\ \ /:::/ / /:::/\:::\ \
/:::/ / /:::/ \:::\ \ /:::/____/ /:::/__\:::\ \
/:::/ / /:::/ / \:::\ \ |::| | /::::\ \:::\ \
/:::/ / /:::/____/ \:::\____\ |::| | _____ /::::::\ \:::\ \
/:::/ / |:::| | |:::| | |::| | /\ \ /:::/\:::\ \:::\ \
/:::/____/ |:::|____| |:::| | |::| | /::\____\/:::/__\:::\ \:::\____\
\:::\ \ \:::\ \ /:::/ / |::| | /:::/ /\:::\ \:::\ \::/ /
\:::\ \ \:::\ \ /:::/ / |::| | /:::/ / \:::\ \:::\ \/____/
\:::\ \ \:::\ /:::/ / |::|____|/:::/ / \:::\ \:::\ \
\:::\ \ \:::\__/:::/ / |:::::::::::/ / \:::\ \:::\____\
\:::\ \ \::::::::/ / \::::::::::/____/ \:::\ \::/ /
\:::\ \ \::::::/ / ~~~~~~~~~~ \:::\ \/____/
\:::\ \ \::::/ / \:::\ \
\:::\____\ \::/____/ \:::\____\
\::/ / ~~ \::/ /
\/____/ \/____/