Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
a54e2871
Commit
a54e2871
authored
May 18, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
a2a010f0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
9 deletions
+87
-9
YzgTimeout.java
...src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
+34
-6
YzgTimeoutHeart.java
...ain/java/com/yanzuoguang/util/helper/YzgTimeoutHeart.java
+15
-0
PlanInfo.java
...l-redis/src/main/java/com.yanzuoguang.redis/PlanInfo.java
+26
-1
PlanService.java
.../main/java/com.yanzuoguang.redis/service/PlanService.java
+12
-2
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
View file @
a54e2871
...
...
@@ -11,7 +11,7 @@ import com.yanzuoguang.util.vo.Ref;
*/
public
class
YzgTimeout
{
public
static
final
long
TIME_OUT_DEFAULT
=
15
*
1000
;
public
static
final
int
TIME_OUT_DEFAULT
=
15
*
1000
;
public
static
final
int
TIME_OUT_TIP
=
10
*
1000
;
public
static
final
int
TIME_OUT_UNIT
=
10
;
...
...
@@ -23,19 +23,45 @@ public class YzgTimeout {
* @param runnable 运行函数
*/
public
static
void
timeOut
(
Class
<?>
cls
,
String
message
,
Runnable
runnable
)
{
timeHeart
(
TIME_OUT_DEFAULT
,
TIME_OUT_UNIT
,
TIME_OUT_TIP
,
runnable
,
(
time
)
->
{
Log
.
error
(
cls
,
"%s超时,已经执行%d豪秒,正在等待执行完成"
,
message
,
time
);
});
}
/**
* 超时监控
*
* @param runnable 运行函数
* @param heart 心跳函数
*/
public
static
void
timeHeart
(
Runnable
runnable
,
YzgTimeoutHeart
heart
)
{
timeHeart
(
1000
,
1000
,
10
,
runnable
,
heart
);
}
/**
* 超时监控
*
* @param tipOutDefault 默认超时时间
* @param timeOutTip 超时心跳间隔
* @param tipUnit 监听间隔时间(监听任务完成间隔时间)
* @param runnable 运行函数
* @param heart 心跳函数
*/
public
static
void
timeHeart
(
int
tipOutDefault
,
int
timeOutTip
,
int
tipUnit
,
Runnable
runnable
,
YzgTimeoutHeart
heart
)
{
final
Ref
<
Boolean
>
isRun
=
new
Ref
<>(
false
);
ThreadHelper
.
runThread
(()
->
{
try
{
long
timeMax
=
TIME_OUT_DEFAULT
;
long
timeMax
=
tipOutDefault
;
long
start
=
System
.
currentTimeMillis
();
do
{
ThreadHelper
.
sleep
(
TIME_OUT_UNIT
);
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
start
;
if
(
time
>
timeMax
)
{
timeMax
+=
TIME_OUT_TIP
;
Log
.
error
(
cls
,
"%s超时,已经执行%d豪秒,正在等待执行完成"
,
message
,
time
);
timeMax
+=
timeOutTip
;
heart
.
heart
(
time
);
}
ThreadHelper
.
sleep
(
tipUnit
);
}
while
(!
isRun
.
value
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
...
...
@@ -44,7 +70,9 @@ public class YzgTimeout {
try
{
runnable
.
run
();
}
finally
{
synchronized
(
isRun
)
{
isRun
.
value
=
true
;
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/YzgTimeoutHeart.java
0 → 100644
View file @
a54e2871
package
com
.
yanzuoguang
.
util
.
helper
;
/**
* 超时监控
*
* @author 颜佐光
*/
public
interface
YzgTimeoutHeart
{
/**
* 心跳运行
*
* @param time 已经运行的时间
*/
void
heart
(
long
time
);
}
yzg-util-redis/src/main/java/com.yanzuoguang.redis/PlanInfo.java
View file @
a54e2871
...
...
@@ -10,6 +10,9 @@ import java.util.Date;
* @author 颜佐光
*/
public
class
PlanInfo
<
T
>
{
public
static
final
long
HEART_MAX
=
10
*
1000
;
/**
* 编号,判断时间是否满足
*/
...
...
@@ -19,6 +22,10 @@ public class PlanInfo<T> {
* 获取当前时间是否满足,这里记录上次执行时间(用于时间隔天执行对比)
*/
private
volatile
long
time
;
/**
* 心跳时间
*/
private
volatile
long
heart
;
/**
* 缓存数据
*/
...
...
@@ -64,8 +71,26 @@ public class PlanInfo<T> {
if
(
newId
>
this
.
getId
())
{
return
true
;
}
else
{
return
newId
==
this
.
getId
()
&&
System
.
currentTimeMillis
()
-
this
.
getTime
()
>=
times
;
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
this
.
heart
<
HEART_MAX
)
{
return
false
;
}
return
newId
==
this
.
getId
()
&&
now
-
this
.
getTime
()
>=
times
;
}
}
/**
* 心跳执行函数
*/
public
void
heart
()
{
this
.
heart
=
System
.
currentTimeMillis
();
}
/**
* 心跳执行完成
*/
public
void
heartFinish
()
{
this
.
heart
=
0
;
}
/**
...
...
yzg-util-redis/src/main/java/com.yanzuoguang.redis/service/PlanService.java
View file @
a54e2871
...
...
@@ -10,6 +10,7 @@ import com.yanzuoguang.redis.mq.PlanProcedure;
import
com.yanzuoguang.redis.vo.PlanConfigVo
;
import
com.yanzuoguang.redis.vo.PlanLevelType
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.YzgTimeout
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
...
...
@@ -78,8 +79,17 @@ public class PlanService {
if
(
time
==
null
)
{
return
;
}
YzgTimeout
.
timeHeart
(()
->
{
// 运行任务
planConfigVo
.
getPlan
().
plan
();
},
time1
->
{
timeNew
.
heart
();
// 通知完成写入缓存
cachePlan
.
put
(
key
,
time
);
});
timeNew
.
heartFinish
();
// 通知完成写入缓存
cachePlan
.
put
(
key
,
time
);
});
...
...
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