Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
8974d8f9
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8974d8f9
编写于
12月 09, 2022
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加定时任务
上级
bda9f4ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
0 deletion
+78
-0
src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
...va/com/kwan/springbootkwan/SpringBootKwanApplication.java
+2
-0
src/main/java/com/kwan/springbootkwan/config/ScheduledTaskConfig.java
...a/com/kwan/springbootkwan/config/ScheduledTaskConfig.java
+25
-0
src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java
...n/java/com/kwan/springbootkwan/schedule/ScheduleTest.java
+25
-0
src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java
...ava/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java
+26
-0
未找到文件。
src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java
浏览文件 @
8974d8f9
...
@@ -2,7 +2,9 @@ package com.kwan.springbootkwan;
...
@@ -2,7 +2,9 @@ package com.kwan.springbootkwan;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@EnableScheduling
@SpringBootApplication
@SpringBootApplication
public
class
SpringBootKwanApplication
{
public
class
SpringBootKwanApplication
{
...
...
src/main/java/com/kwan/springbootkwan/config/ScheduledTaskConfig.java
0 → 100644
浏览文件 @
8974d8f9
package
com.kwan.springbootkwan.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.SchedulingConfigurer
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
/**
* scheduler配置类
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/9 14:01
*/
@Configuration
public
class
ScheduledTaskConfig
implements
SchedulingConfigurer
{
@Override
public
void
configureTasks
(
ScheduledTaskRegistrar
taskRegistrar
)
{
ThreadPoolTaskScheduler
taskScheduler
=
new
ThreadPoolTaskScheduler
();
taskScheduler
.
setPoolSize
(
2
);
taskScheduler
.
initialize
();
taskRegistrar
.
setTaskScheduler
(
taskScheduler
);
}
}
src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java
0 → 100644
浏览文件 @
8974d8f9
package
com.kwan.springbootkwan.schedule
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* schedule测试 10s执行一次 记得在启动类或者Configuration类上添加了@EnableScheduling注解。
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/9 13:58
*/
@Component
@Slf4j
public
class
ScheduleTest
{
@Scheduled
(
cron
=
"0/10 * * * * ?"
)
public
void
execute
()
{
log
.
info
(
"Scheduled task is running ... ..."
);
}
}
src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java
0 → 100644
浏览文件 @
8974d8f9
package
com.kwan.springbootkwan.schedule
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
/**
* schedule测试
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/9 14:01
*/
@Component
@Slf4j
public
class
ScheduleTestTwo
{
@Scheduled
(
cron
=
"0/10 * * * * *"
)
public
void
second
()
throws
InterruptedException
{
log
.
info
(
"Second scheduled task is running... ..."
);
TimeUnit
.
SECONDS
.
sleep
(
5
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录