Commit d4ae3360 authored by yanzg's avatar yanzg

升级新版本

parent 7fe8feb4
...@@ -4,10 +4,7 @@ import com.yanzuoguang.util.exception.ExceptionHelper; ...@@ -4,10 +4,7 @@ import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
import java.util.Date; import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate; import java.util.function.Predicate;
/** /**
...@@ -23,12 +20,10 @@ public class ThreadHelper { ...@@ -23,12 +20,10 @@ public class ThreadHelper {
private static RunPlan interval; private static RunPlan interval;
private static final long SECOND_UNIT = 1000; private static final long SECOND_UNIT = 1000;
private static final long NEXT_SECOND = 5; private static final long NEXT_SECOND = 5;
private static final int THREAD_SIZE = 10000;
/** /**
* 线程对象 * 线程对象
*/ */
private static final ExecutorService executeService = new ThreadPoolExecutor(1, THREAD_SIZE, 1000, private static final ExecutorService executeService = Executors.newCachedThreadPool();
TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(THREAD_SIZE));
/** /**
* 初始化线程对象,需要调用该函数之后才能使用 * 初始化线程对象,需要调用该函数之后才能使用
......
...@@ -6,15 +6,14 @@ import org.junit.Test; ...@@ -6,15 +6,14 @@ import org.junit.Test;
public class TestTimeout { public class TestTimeout {
public static final int WAIT_TIME = 1 * 60 * 1000;
@Test @Test
public void test() { public void test() {
YzgTimeout.timeOut(TestTimeout.class, "消息", new Runnable() { YzgTimeout.timeOut(TestTimeout.class, "消息", () -> {
@Override System.out.println("开始运行");
public void run() { ThreadHelper.sleep(WAIT_TIME);
System.out.println("开始运行"); System.out.println("结束运行");
ThreadHelper.sleep(1 * 60 * 1000);
System.out.println("结束运行");
}
}, (time) -> { }, (time) -> {
// System.err.println("已经等待" + time); // System.err.println("已经等待" + time);
}); });
...@@ -22,8 +21,9 @@ public class TestTimeout { ...@@ -22,8 +21,9 @@ public class TestTimeout {
@Test @Test
public void testQueue() { public void testQueue() {
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 5000; i++) {
ThreadHelper.runThread(() -> test()); ThreadHelper.runThread(() -> test());
} }
ThreadHelper.sleep(WAIT_TIME * 2);
} }
} }
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