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
b3a81e83
Commit
b3a81e83
authored
Sep 20, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ver1.1' of
http://192.168.0.204/yzg/yzg-util
parents
9b7f1ed0
95d52d47
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
YzgTimeout.java
...src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
+18
-13
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/YzgTimeout.java
View file @
b3a81e83
...
...
@@ -4,10 +4,7 @@ import com.yanzuoguang.util.log.Log;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
java.util.Queue
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.*
;
import
java.util.function.Consumer
;
/**
...
...
@@ -20,7 +17,7 @@ public class YzgTimeout {
public
static
final
int
TIME_OUT_DEFAULT
=
15
*
1000
;
public
static
final
int
TIME_OUT_TIP
=
10
*
1000
;
private
static
ExecutorService
executorService
;
private
static
final
Queue
<
TimeInfo
>
queueInfos
=
new
ArrayBlockingQueue
<>(
Integer
.
MAX_VALUE
);
private
static
final
Queue
<
TimeInfo
>
queueInfos
=
new
ConcurrentLinkedQueue
<>(
);
/**
...
...
@@ -74,16 +71,16 @@ public class YzgTimeout {
try
{
runnable
.
run
();
}
finally
{
synchronized
(
timeInfo
)
{
timeInfo
.
setRun
(
true
);
}
}
}
private
static
TimeInfo
getTimeInfo
(
int
tipOutDefault
,
int
timeOutTip
,
YzgTimeoutHeart
heart
)
{
init
();
TimeInfo
timeInfo
=
new
TimeInfo
(
tipOutDefault
,
timeOutTip
,
heart
);
synchronized
(
queueInfos
)
{
queueInfos
.
add
(
timeInfo
);
}
return
timeInfo
;
}
...
...
@@ -106,24 +103,32 @@ public class YzgTimeout {
}
private
static
void
runItem
()
{
int
size
=
queueInfos
.
size
();
int
size
;
synchronized
(
queueInfos
)
{
size
=
queueInfos
.
size
();
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
TimeInfo
poll
=
queueInfos
.
poll
();
TimeInfo
poll
;
synchronized
(
queueInfos
)
{
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
));
executorService
.
execute
(()
->
poll
.
getHeart
().
heart
(
time
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
if
(!
poll
.
isRun
())
{
synchronized
(
queueInfos
)
{
queueInfos
.
add
(
poll
);
}
}
}
}
}
class
TimeInfo
{
...
...
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