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
21e9a9f1
Commit
21e9a9f1
authored
May 07, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消除成功接收处理
parent
3c65703d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
39 deletions
+46
-39
RunnableListAuto.java
...in/java/com/yanzuoguang/util/thread/RunnableListAuto.java
+46
-39
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableListAuto.java
View file @
21e9a9f1
...
@@ -61,10 +61,6 @@ public final class RunnableListAuto {
...
@@ -61,10 +61,6 @@ public final class RunnableListAuto {
* @param methods
* @param methods
*/
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
List
<
RunnableListAutoItem
>
methods
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
List
<
RunnableListAutoItem
>
methods
)
{
// 获取历史执行时间
int
zeroCount
=
0
;
long
totalAvg
=
0
;
long
maxAvg
=
0
;
// 没有执行过的列表
// 没有执行过的列表
List
<
RunnableListAutoItem
>
initList
=
new
ArrayList
<
RunnableListAutoItem
>();
List
<
RunnableListAutoItem
>
initList
=
new
ArrayList
<
RunnableListAutoItem
>();
...
@@ -72,6 +68,51 @@ public final class RunnableListAuto {
...
@@ -72,6 +68,51 @@ public final class RunnableListAuto {
Map
<
String
,
List
<
RunnableListAutoItem
>>
executeMap
=
new
HashMap
<>(
20
);
Map
<
String
,
List
<
RunnableListAutoItem
>>
executeMap
=
new
HashMap
<>(
20
);
// 已执行过的列表
// 已执行过的列表
List
<
RunnableListAutoItem
>
executedToList
=
new
ArrayList
<
RunnableListAutoItem
>();
List
<
RunnableListAutoItem
>
executedToList
=
new
ArrayList
<
RunnableListAutoItem
>();
int
threadCount
=
initPlan
(
methods
,
initList
,
executeMap
,
executedToList
);
// 打印线程顺序
if
(
IsLog
)
{
for
(
RunnableListAutoItem
item
:
initList
)
{
if
(
item
==
null
)
{
continue
;
}
RunnableListAutoItem
toItem
=
cache
.
get
(
item
.
getKey
());
writeLog
(
"上次执行时间"
,
toItem
,
threadCount
);
}
}
// 开始线程列表
AbstractThreadList
<
RunnableListAutoItem
>
threadList
=
new
AbstractThreadList
<
RunnableListAutoItem
>(
threadCount
)
{
@Override
public
void
run
(
RunnableListAutoItem
item
)
{
try
{
item
.
execute
();
if
(
IsLog
)
{
writeLog
(
"执行时间"
,
item
,
threadCount
);
}
}
finally
{
RunnableListAutoItem
to
=
cache
.
get
(
item
.
getKey
());
to
.
add
(
item
);
}
}
};
// 添加到执行列表
threadList
.
add
(
initList
);
// 等待线程执行完成
threadList
.
waitRun
();
return
threadList
;
}
private
static
int
initPlan
(
List
<
RunnableListAutoItem
>
methods
,
List
<
RunnableListAutoItem
>
initList
,
Map
<
String
,
List
<
RunnableListAutoItem
>>
executeMap
,
List
<
RunnableListAutoItem
>
executedToList
)
{
// 获取历史执行时间
int
zeroCount
=
0
;
long
totalAvg
=
0
;
long
maxAvg
=
0
;
// 缓存的执行对象
// 缓存的执行对象
for
(
RunnableListAutoItem
from
:
methods
)
{
for
(
RunnableListAutoItem
from
:
methods
)
{
...
@@ -114,42 +155,8 @@ public final class RunnableListAuto {
...
@@ -114,42 +155,8 @@ public final class RunnableListAuto {
if
(
threadCount
>
MIN_THREAD
)
{
if
(
threadCount
>
MIN_THREAD
)
{
threadCount
=
threadCount
-
1
;
threadCount
=
threadCount
-
1
;
}
}
threadCount
=
Math
.
min
(
threadCount
,
methods
.
size
());
final
int
finalThreadCount
=
threadCount
;
// 打印线程顺序
if
(
IsLog
)
{
for
(
RunnableListAutoItem
item
:
initList
)
{
if
(
item
==
null
)
{
continue
;
}
RunnableListAutoItem
toItem
=
cache
.
get
(
item
.
getKey
());
writeLog
(
"上次执行时间"
,
toItem
,
finalThreadCount
);
}
}
// 开始线程列表
return
Math
.
min
(
threadCount
,
methods
.
size
());
AbstractThreadList
<
RunnableListAutoItem
>
threadList
=
new
AbstractThreadList
<
RunnableListAutoItem
>(
finalThreadCount
)
{
@Override
public
void
run
(
RunnableListAutoItem
item
)
{
try
{
item
.
execute
();
if
(
IsLog
)
{
writeLog
(
"执行时间"
,
item
,
finalThreadCount
);
}
}
finally
{
RunnableListAutoItem
to
=
cache
.
get
(
item
.
getKey
());
to
.
add
(
item
);
}
}
};
// 添加到执行列表
threadList
.
add
(
initList
);
// 等待线程执行完成
threadList
.
waitRun
();
return
threadList
;
}
}
private
static
void
writeLog
(
String
tag
,
RunnableListAutoItem
item
,
int
threadCount
)
{
private
static
void
writeLog
(
String
tag
,
RunnableListAutoItem
item
,
int
threadCount
)
{
...
...
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