Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
messageflow
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
虞诚毅
messageflow
Commits
952116fc
Commit
952116fc
authored
Apr 27, 2018
by
shentao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2018/4/27 超时控制
parent
66bad2e5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
16 deletions
+28
-16
src/main/java/com/zhiwei/messageflow/ES4RedisTask.java
+1
-2
src/main/java/com/zhiwei/messageflow/ES4RedisThread.java
+27
-14
src/main/resources/application.properties.local2
+0
-0
No files found.
src/main/java/com/zhiwei/messageflow/ES4RedisTask.java
View file @
952116fc
...
...
@@ -378,8 +378,7 @@ public class ES4RedisTask {
log
.
info
(
"{}项目本次获取消息数:{}"
,
project
.
getProjectName
(),
num
);
}
catch
(
Exception
e
)
{
log
.
error
(
"{} {}"
,
e
.
getMessage
(),
e
.
getStackTrace
());
e
.
printStackTrace
();
log
.
error
(
"项目本次获取获取出错或超时{}{}"
,
e
.
getMessage
(),
e
.
getStackTrace
());
return
false
;
}
return
true
;
...
...
src/main/java/com/zhiwei/messageflow/ES4RedisThread.java
View file @
952116fc
...
...
@@ -64,6 +64,18 @@ public class ES4RedisThread extends Thread {
// 通知执行run方法
t
.
start
();
}
// 超时控制器
Timer
timer
=
new
Timer
();
timer
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
// 超时则线程中止
if
(
t
.
isAlive
())
{
t
.
interrupt
();
log
.
warn
(
"{}项目超时线程状态:{}"
,
project
.
getProjectName
(),
t
.
isInterrupted
());
}
}
},
49
*
1000L
);
}
@SuppressWarnings
(
"static-access"
)
...
...
@@ -74,15 +86,15 @@ public class ES4RedisThread extends Thread {
Thread
.
sleep
(
10L
);
// 超时控制器
Timer
timer
=
new
Timer
();
timer
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
// 超时则线程中止
Thread
.
currentThread
().
interrupted
();
log
.
warn
(
"{}项目超时"
,
project
.
getProjectName
());
}
},
49
*
1000L
);
//
Timer timer = new Timer();
//
timer.schedule(new TimerTask() {
//
@Override
//
public void run() {
//
// 超时则线程中止
//
Thread.currentThread().interrupted();
//
log.warn("{}项目超时", project.getProjectName());
//
}
//
}, 49 * 1000L);
// 程序运行
log
.
info
(
"Running {}"
,
threadName
);
...
...
@@ -92,12 +104,13 @@ public class ES4RedisThread extends Thread {
if
(!
flag
)
{
// 程序执行出现异常则线程中止
timer
.
cancel
();
//
timer.cancel();
Thread
.
currentThread
().
interrupted
();
log
.
error
(
"{}项目出现异常"
,
project
.
getProjectName
());
}
else
// 程序正常执行完毕,关闭超时控制器
timer
.
cancel
();
log
.
error
(
"{}项目出现异常,线程状态:{}"
,
project
.
getProjectName
(),
Thread
.
currentThread
().
isInterrupted
());
}
// else
// // 程序正常执行完毕,关闭超时控制器
// timer.cancel();
}
catch
(
JsonParseException
e
)
{
e
.
printStackTrace
();
...
...
src/main/resources/application.properties.2
→
src/main/resources/application.properties.
local
2
View file @
952116fc
File moved
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