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
35ebe843
Commit
35ebe843
authored
May 19, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
f11c0a43
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
Timeout.java
...loud/src/main/java/com/yanzuoguang/cloud/aop/Timeout.java
+4
-3
TestTimeout.java
yzg-util-cloud/src/test/java/TestTimeout.java
+27
-0
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/Timeout.java
View file @
35ebe843
...
...
@@ -66,10 +66,11 @@ public class Timeout<T> {
return
false
;
}
long
prevTime
=
now
-
prev
;
try
{
return
prevMaxTime
>
prev
Time
;
}
finally
{
// System.out.println(String.format("now %d time %d prev %d prevTime %d ", now, time, prev, prevTime))
boolean
ret
=
prevTime
>
prevMax
Time
;
if
(
ret
)
{
this
.
prev
=
now
;
}
return
ret
;
}
}
yzg-util-cloud/src/test/java/TestTimeout.java
0 → 100644
View file @
35ebe843
import
com.yanzuoguang.cloud.aop.Timeout
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
public
class
TestTimeout
{
@Test
public
void
testTimeout
()
{
Timeout
<
Integer
>
timeout
=
new
Timeout
<>(
1
);
long
maxTime
=
1000
;
long
start
=
System
.
currentTimeMillis
();
long
prev
=
start
;
while
(
maxTime
>
0
)
{
long
now
=
System
.
currentTimeMillis
();
long
runTime
=
now
-
start
;
long
waitTime
=
now
-
prev
;
prev
=
now
;
maxTime
-=
waitTime
;
if
(
timeout
.
isMaxTime
(
10
,
20
))
{
System
.
out
.
println
(
"执行时间"
+
runTime
);
}
ThreadHelper
.
sleep
(
10
);
}
}
}
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