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
ca5fa79b
Commit
ca5fa79b
authored
May 15, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置打包时可以通过GIT查看源码
parent
0b137097
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
AbstractThreadList.java
.../java/com/yanzuoguang/util/thread/AbstractThreadList.java
+11
-4
TestRunnableListAuto.java
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
+32
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/AbstractThreadList.java
View file @
ca5fa79b
...
...
@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
/**
* 多线程处理队列
*
* @author 颜佐光
*/
public
abstract
class
AbstractThreadList
<
T
extends
Object
>
implements
ThreadWaitExecute
{
...
...
@@ -46,7 +47,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
/**
* 缓存的异常数据
*/
private
RuntimeException
exception
;
private
List
<
RuntimeException
>
exceptions
=
new
ArrayList
<>()
;
/**
* 等待对象
...
...
@@ -167,6 +168,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
if
(
threadListNum
.
getRowTotal
()
<
1
)
{
return
;
}
exceptions
.
clear
();
int
threadCount
=
Math
.
min
(
this
.
threadCount
,
threadListNum
.
getRowTotal
());
// 开启剩余线程数量
for
(
int
i
=
cacheThread
.
size
();
i
<
threadCount
;
i
++)
{
...
...
@@ -300,6 +302,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
public
void
waitRun
()
{
this
.
threadExecute
();
threadWait
.
waitFinally
();
this
.
throwThreadError
();
}
/**
...
...
@@ -325,15 +328,19 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
* @param ex
*/
private
void
logError
(
RuntimeException
ex
)
{
this
.
exception
=
ex
;
synchronized
(
this
)
{
this
.
exceptions
.
add
(
ex
);
}
}
/**
* 抛出线程中的异常数据
*/
public
AbstractThreadList
<
T
>
throwThreadError
()
{
if
(
this
.
exception
!=
null
)
{
throw
this
.
exception
;
synchronized
(
this
)
{
if
(!
this
.
exceptions
.
isEmpty
())
{
throw
this
.
exceptions
.
get
(
0
);
}
}
return
this
;
}
...
...
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
0 → 100644
View file @
ca5fa79b
package
thread
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.thread.RunnableListAuto
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
public
class
TestRunnableListAuto
{
@Test
public
void
test
()
{
try
{
RunnableListAuto
.
run
(
new
Runnable
()
{
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
1000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
},
new
Runnable
()
{
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
2000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
});
throw
new
CodeException
(
"没有抛出异常"
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
TestRunnableListAuto
.
class
,
ex
);
}
}
}
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