Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
38f9de5f
Commit
38f9de5f
authored
Mar 27, 2019
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加spring定时任务
parent
e2a03854
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
0 deletions
+85
-0
src/main/java/cn/stylefeng/guns/GunsApplication.java
+2
-0
src/main/java/cn/stylefeng/guns/config/SchedulingConfig.java
+26
-0
src/main/java/cn/stylefeng/guns/core/schedue/SpringTasks.java
+57
-0
No files found.
src/main/java/cn/stylefeng/guns/GunsApplication.java
View file @
38f9de5f
...
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
...
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
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
;
/**
/**
* SpringBoot方式启动类
* SpringBoot方式启动类
...
@@ -28,6 +29,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
...
@@ -28,6 +29,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Date 2017/5/21 12:06
* @Date 2017/5/21 12:06
*/
*/
@SpringBootApplication
(
exclude
=
{
WebAutoConfiguration
.
class
})
@SpringBootApplication
(
exclude
=
{
WebAutoConfiguration
.
class
})
@EnableScheduling
public
class
GunsApplication
{
public
class
GunsApplication
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
GunsApplication
.
class
);
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
GunsApplication
.
class
);
...
...
src/main/java/cn/stylefeng/guns/config/SchedulingConfig.java
0 → 100644
View file @
38f9de5f
package
cn
.
stylefeng
.
guns
.
config
;
import
cn.stylefeng.guns.core.schedue.SpringTasks
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* 定时任务自动配置
*
* @author fengshuonan
* @Date 2019/2/24 16:23
*/
@Configuration
public
class
SchedulingConfig
{
/**
* 定时任务执行测试,注意在Application上加@EnableScheduling
*
* @author fengshuonan
* @Date 2019/3/27 2:48 PM
*/
@Bean
public
SpringTasks
scheduledTasks
()
{
return
new
SpringTasks
();
}
}
src/main/java/cn/stylefeng/guns/core/schedue/SpringTasks.java
0 → 100644
View file @
38f9de5f
package
cn
.
stylefeng
.
guns
.
core
.
schedue
;
import
org.springframework.scheduling.annotation.Scheduled
;
/**
* 测试定时任务
*
* @author fengshuonan
* @Date 2019/2/24 16:29
*/
public
class
SpringTasks
{
/**
* 上一次开始执行时间点之后5秒再执行
*
* @author fengshuonan
* @Date 2019/2/24 16:31
*/
@Scheduled
(
fixedRate
=
5000
)
public
void
beginAfter
()
{
System
.
err
.
println
(
"<<<<<调试信息,注释掉SchedulingConfig类中的内容来关闭这个定时任务!>>>>>开始之后5秒执行!"
);
}
/**
* 上一次执行完毕时间点之后5秒再执行
*
* @author fengshuonan
* @Date 2019/2/24 16:31
*/
@Scheduled
(
fixedDelay
=
5000
)
public
void
finishAfter
()
{
System
.
err
.
println
(
"<<<<<调试信息,注释掉SchedulingConfig类中的内容来关闭这个定时任务!>>>>>执行之后5秒才执行!"
);
}
/**
* 上一次执行完毕时间点之后5秒再执行
*
* @author fengshuonan
* @Date 2019/2/24 16:31
*/
@Scheduled
(
initialDelay
=
1000
,
fixedRate
=
5000
)
public
void
stepAdd
()
{
System
.
err
.
println
(
"<<<<<调试信息,注释掉SchedulingConfig类中的内容来关闭这个定时任务!>>>>>第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次!"
);
}
/**
* cron表达式执行
*
* @author fengshuonan
* @Date 2019/2/24 16:31
*/
@Scheduled
(
cron
=
"*/10 * * * * *"
)
public
void
cron
()
{
System
.
err
.
println
(
"<<<<<调试信息,注释掉SchedulingConfig类中的内容来关闭这个定时任务!>>>>>每隔10秒执行一次!"
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment