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;
...
@@ -11,7 +11,7 @@ import com.yanzuoguang.util.vo.Ref;
*/
*/
public
class
YzgTimeout
{
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_TIP
=
10
*
1000
;
public
static
final
int
TIME_OUT_UNIT
=
10
;
public
static
final
int
TIME_OUT_UNIT
=
10
;
...
@@ -23,19 +23,45 @@ public class YzgTimeout {
...
@@ -23,19 +23,45 @@ public class YzgTimeout {
* @param runnable 运行函数
* @param runnable 运行函数
*/
*/
public
static
void
timeOut
(
Class
<?>
cls
,
String
message
,
Runnable
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
);
final
Ref
<
Boolean
>
isRun
=
new
Ref
<>(
false
);
ThreadHelper
.
runThread
(()
->
{
ThreadHelper
.
runThread
(()
->
{
try
{
try
{
long
timeMax
=
TIME_OUT_DEFAULT
;
long
timeMax
=
tipOutDefault
;
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
do
{
do
{
ThreadHelper
.
sleep
(
TIME_OUT_UNIT
);
long
end
=
System
.
currentTimeMillis
();
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
start
;
long
time
=
end
-
start
;
if
(
time
>
timeMax
)
{
if
(
time
>
timeMax
)
{
timeMax
+=
TIME_OUT_TIP
;
timeMax
+=
timeOutTip
;
Log
.
error
(
cls
,
"%s超时,已经执行%d豪秒,正在等待执行完成"
,
message
,
time
);
heart
.
heart
(
time
);
}
}
ThreadHelper
.
sleep
(
tipUnit
);
}
while
(!
isRun
.
value
);
}
while
(!
isRun
.
value
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
ex
.
printStackTrace
();
...
@@ -44,7 +70,9 @@ public class YzgTimeout {
...
@@ -44,7 +70,9 @@ public class YzgTimeout {
try
{
try
{
runnable
.
run
();
runnable
.
run
();
}
finally
{
}
finally
{
synchronized
(
isRun
)
{
isRun
.
value
=
true
;
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;
...
@@ -10,6 +10,9 @@ import java.util.Date;
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
PlanInfo
<
T
>
{
public
class
PlanInfo
<
T
>
{
public
static
final
long
HEART_MAX
=
10
*
1000
;
/**
/**
* 编号,判断时间是否满足
* 编号,判断时间是否满足
*/
*/
...
@@ -19,6 +22,10 @@ public class PlanInfo<T> {
...
@@ -19,6 +22,10 @@ public class PlanInfo<T> {
* 获取当前时间是否满足,这里记录上次执行时间(用于时间隔天执行对比)
* 获取当前时间是否满足,这里记录上次执行时间(用于时间隔天执行对比)
*/
*/
private
volatile
long
time
;
private
volatile
long
time
;
/**
* 心跳时间
*/
private
volatile
long
heart
;
/**
/**
* 缓存数据
* 缓存数据
*/
*/
...
@@ -64,8 +71,26 @@ public class PlanInfo<T> {
...
@@ -64,8 +71,26 @@ public class PlanInfo<T> {
if
(
newId
>
this
.
getId
())
{
if
(
newId
>
this
.
getId
())
{
return
true
;
return
true
;
}
else
{
}
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;
...
@@ -10,6 +10,7 @@ import com.yanzuoguang.redis.mq.PlanProcedure;
import
com.yanzuoguang.redis.vo.PlanConfigVo
;
import
com.yanzuoguang.redis.vo.PlanConfigVo
;
import
com.yanzuoguang.redis.vo.PlanLevelType
;
import
com.yanzuoguang.redis.vo.PlanLevelType
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.YzgTimeout
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -78,8 +79,17 @@ public class PlanService {
...
@@ -78,8 +79,17 @@ public class PlanService {
if
(
time
==
null
)
{
if
(
time
==
null
)
{
return
;
return
;
}
}
YzgTimeout
.
timeHeart
(()
->
{
// 运行任务
// 运行任务
planConfigVo
.
getPlan
().
plan
();
planConfigVo
.
getPlan
().
plan
();
},
time1
->
{
timeNew
.
heart
();
// 通知完成写入缓存
cachePlan
.
put
(
key
,
time
);
});
timeNew
.
heartFinish
();
// 通知完成写入缓存
// 通知完成写入缓存
cachePlan
.
put
(
key
,
time
);
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