Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
customer-service
Commits
25a28eb7
Commit
25a28eb7
authored
May 14, 2024
by
yajun.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
16800baa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
DatabaseConnectionKeeper.java
...tgroup/customer/config/data/DatabaseConnectionKeeper.java
+5
-1
No files found.
src/main/java/cn/quantgroup/customer/config/data/DatabaseConnectionKeeper.java
View file @
25a28eb7
...
...
@@ -3,12 +3,14 @@ package cn.quantgroup.customer.config.data;
import
cn.hutool.log.Log
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
@Slf4j
@Component
public
class
DatabaseConnectionKeeper
{
...
...
@@ -22,10 +24,12 @@ public class DatabaseConnectionKeeper {
// 每小时执行一次查询操作,保持数据库连接活跃
@Scheduled
(
fixedDelay
=
60000
)
// 每小时执行一次
public
void
keepDatabaseConnectionAlive
()
{
log
.
info
(
"数据库定时任务执行"
);
try
{
jdbcTemplate
.
execute
(
"SELECT 1"
);
// 执行一个简单的查询操作
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
x
)
{
// 处理异常
log
.
error
(
"数据库定时任务执行异常"
,
ex
);
}
}
}
\ 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