Commit ecbad115 authored by yanzg's avatar yanzg

设置打包时可以通过GIT查看源码

parent ca5fa79b
......@@ -9,6 +9,7 @@ import java.util.Vector;
/**
* 内存缓存中心,负责自动清除过期缓存
*
* @author 颜佐光
*/
public class MemoryCacheCenter {
......@@ -52,6 +53,6 @@ public class MemoryCacheCenter {
}
};
threadList.add(CLEAR_LIST);
threadList.waitRun();
threadList.waitRun(false);
}
}
......@@ -300,9 +300,18 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
* 开启等待线程,一直等待到全部执行完毕
*/
public void waitRun() {
this.waitRun(true);
}
/**
* 开启等待线程,一直等待到全部执行完毕
*/
public void waitRun(boolean throwError) {
this.threadExecute();
threadWait.waitFinally();
this.throwThreadError();
if (throwError) {
this.throwThreadError();
}
}
/**
......@@ -333,6 +342,15 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
}
}
/**
* 获取所有错误信息
*
* @return 获取所有的错误信息
*/
public List<RuntimeException> getExceptions() {
return exceptions;
}
/**
* 抛出线程中的异常数据
*/
......
......@@ -30,7 +30,7 @@ public final class RunnableListAuto {
* @param codes
*/
public static AbstractThreadList<RunnableListAutoItem> run(Runnable... codes) {
return run(Arrays.asList(codes));
return run(false, codes);
}
/**
......@@ -39,11 +39,41 @@ public final class RunnableListAuto {
* @param codes
*/
public static AbstractThreadList<RunnableListAutoItem> run(List<Runnable> codes) {
return run(false, codes);
}
/**
* 将数据进行整理
*
* @param codes
* @return
*/
private static List<RunnableListAutoItem> convertRun(List<Runnable> codes) {
List<RunnableListAutoItem> autos = new ArrayList<RunnableListAutoItem>();
for (Runnable code : codes) {
autos.add(new RunnableListAutoItem(code));
}
return runAuto(autos);
return autos;
}
/**
* 自动开启线程去执行代码,并根据执行时间调整先后顺序
*
* @param codes
*/
public static AbstractThreadList<RunnableListAutoItem> run(boolean throwError, Runnable... codes) {
List<RunnableListAutoItem> autos = convertRun(Arrays.asList(codes));
return runAuto(throwError, autos);
}
/**
* 自动开启线程去执行代码,并根据执行时间调整先后顺序
*
* @param codes
*/
public static AbstractThreadList<RunnableListAutoItem> run(boolean throwError, List<Runnable> codes) {
List<RunnableListAutoItem> autos = convertRun(codes);
return runAuto(throwError, autos);
}
/**
......@@ -52,7 +82,7 @@ public final class RunnableListAuto {
* @param methods
*/
public static AbstractThreadList<RunnableListAutoItem> runAuto(RunnableListAutoItem... methods) {
return runAuto(Arrays.asList(methods));
return runAuto(false, Arrays.asList(methods));
}
/**
......@@ -60,7 +90,7 @@ public final class RunnableListAuto {
*
* @param methods
*/
public static AbstractThreadList<RunnableListAutoItem> runAuto(List<RunnableListAutoItem> methods) {
public static AbstractThreadList<RunnableListAutoItem> runAuto(boolean throwError, List<RunnableListAutoItem> methods) {
// 没有执行过的列表
List<RunnableListAutoItem> initList = new ArrayList<RunnableListAutoItem>();
......@@ -100,7 +130,7 @@ public final class RunnableListAuto {
// 添加到执行列表
threadList.add(initList);
// 等待线程执行完成
threadList.waitRun();
threadList.waitRun(throwError);
return threadList;
}
......
......@@ -8,25 +8,34 @@ import org.junit.Test;
public class TestRunnableListAuto {
private void runTest(boolean throwError) {
RunnableListAuto.run(throwError, 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秒秒");
}
});
}
@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秒秒");
}
});
runTest(true);
throw new CodeException("没有抛出异常");
} catch (Exception ex) {
Log.error(TestRunnableListAuto.class, ex);
// Log.error(TestRunnableListAuto.class, ex);
}
}
@Test
public void test1() {
runTest(false);
}
}
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