Commit ca5fa79b authored by yanzg's avatar yanzg

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

parent 0b137097
......@@ -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;
}
......
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);
}
}
}
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