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
552c2c68
Commit
552c2c68
authored
Sep 19, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复实体关系
parent
6b71ce70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
17 deletions
+68
-17
YzgTimeout.java
...src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
+46
-17
TestTimeout.java
yzg-util-base/src/test/java/helper/TestTimeout.java
+22
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
View file @
552c2c68
...
...
@@ -95,23 +95,32 @@ public class YzgTimeout {
}
}
ThreadHelper
.
runThread
(()
->
{
try
{
long
timeMax
=
tipOutDefault
;
long
start
=
System
.
currentTimeMillis
();
do
{
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
start
;
if
(
time
>
timeMax
)
{
timeMax
+=
timeOutTip
;
heart
.
heart
(
time
);
}
ThreadHelper
.
sleep
(
tipUnit
);
}
while
(!
isRun
.
value
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
while
(
true
)
{
runItem
();
ThreadHelper
.
sleep
(
1000
);
}
});
}
private
static
void
runItem
()
{
int
size
=
queueInfos
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
TimeInfo
poll
=
queueInfos
.
poll
();
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
poll
.
getStart
();
if
(
time
>
poll
.
getTimeMax
())
{
try
{
poll
.
setTimeMax
(
poll
.
getTimeMax
()
+
poll
.
getTimeOutTip
());
executorService
.
submit
(()
->
poll
.
getHeart
().
heart
(
time
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
if
(!
poll
.
isRun
())
{
queueInfos
.
add
(
poll
);
}
}
}
}
class
TimeInfo
{
...
...
@@ -119,12 +128,16 @@ class TimeInfo {
private
int
timeOutDefault
;
private
int
timeOutTip
;
private
YzgTimeoutHeart
heart
;
private
boolean
isRun
;
private
boolean
run
;
private
long
start
;
private
int
timeMax
;
public
TimeInfo
(
int
timeOutDefault
,
int
timeOutTip
,
YzgTimeoutHeart
heart
)
{
this
.
timeOutDefault
=
timeOutDefault
;
this
.
timeOutTip
=
timeOutTip
;
this
.
heart
=
heart
;
this
.
timeMax
=
timeOutDefault
;
this
.
start
=
System
.
currentTimeMillis
();
}
public
int
getTimeOutDefault
()
{
...
...
@@ -152,10 +165,26 @@ class TimeInfo {
}
public
boolean
isRun
()
{
return
isR
un
;
return
r
un
;
}
public
void
setRun
(
boolean
run
)
{
isRun
=
run
;
this
.
run
=
run
;
}
public
long
getStart
()
{
return
start
;
}
public
void
setStart
(
long
start
)
{
this
.
start
=
start
;
}
public
int
getTimeMax
()
{
return
timeMax
;
}
public
void
setTimeMax
(
int
timeMax
)
{
this
.
timeMax
=
timeMax
;
}
}
yzg-util-base/src/test/java/helper/TestTimeout.java
0 → 100644
View file @
552c2c68
package
helper
;
import
com.yanzuoguang.util.helper.YzgTimeout
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
public
class
TestTimeout
{
@Test
public
void
test
()
{
YzgTimeout
.
timeOut
(
TestTimeout
.
class
,
"消息"
,
new
Runnable
()
{
@Override
public
void
run
()
{
System
.
out
.
println
(
"开始运行"
);
ThreadHelper
.
sleep
(
1
*
60
*
1000
);
System
.
out
.
println
(
"结束运行"
);
}
},
(
time
)
->
{
// System.err.println("已经等待" + 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