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
d4ae3360
Commit
d4ae3360
authored
Sep 20, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级新版本
parent
7fe8feb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
+10
-15
ThreadHelper.java
...c/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
+2
-7
TestTimeout.java
yzg-util-base/src/test/java/helper/TestTimeout.java
+8
-8
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
View file @
d4ae3360
...
...
@@ -4,10 +4,7 @@ import com.yanzuoguang.util.exception.ExceptionHelper;
import
com.yanzuoguang.util.helper.DateHelper
;
import
java.util.Date
;
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.Predicate
;
/**
...
...
@@ -23,12 +20,10 @@ public class ThreadHelper {
private
static
RunPlan
interval
;
private
static
final
long
SECOND_UNIT
=
1000
;
private
static
final
long
NEXT_SECOND
=
5
;
private
static
final
int
THREAD_SIZE
=
10000
;
/**
* 线程对象
*/
private
static
final
ExecutorService
executeService
=
new
ThreadPoolExecutor
(
1
,
THREAD_SIZE
,
1000
,
TimeUnit
.
MILLISECONDS
,
new
ArrayBlockingQueue
<>(
THREAD_SIZE
));
private
static
final
ExecutorService
executeService
=
Executors
.
newCachedThreadPool
();
/**
* 初始化线程对象,需要调用该函数之后才能使用
...
...
yzg-util-base/src/test/java/helper/TestTimeout.java
View file @
d4ae3360
...
...
@@ -6,15 +6,14 @@ import org.junit.Test;
public
class
TestTimeout
{
public
static
final
int
WAIT_TIME
=
1
*
60
*
1000
;
@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
(
"结束运行"
);
}
YzgTimeout
.
timeOut
(
TestTimeout
.
class
,
"消息"
,
()
->
{
System
.
out
.
println
(
"开始运行"
);
ThreadHelper
.
sleep
(
WAIT_TIME
);
System
.
out
.
println
(
"结束运行"
);
},
(
time
)
->
{
// System.err.println("已经等待" + time);
});
...
...
@@ -22,8 +21,9 @@ public class TestTimeout {
@Test
public
void
testQueue
()
{
for
(
int
i
=
0
;
i
<
10
000
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
000
;
i
++)
{
ThreadHelper
.
runThread
(()
->
test
());
}
ThreadHelper
.
sleep
(
WAIT_TIME
*
2
);
}
}
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