Commit 21e9a9f1 authored by yanzg's avatar yanzg

消除成功接收处理

parent 3c65703d
...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment