|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package cn.hippo4j.example.inittest;
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper;
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@ -7,6 +8,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -19,27 +21,38 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
@Component
|
|
|
|
|
public class RunStateHandlerTest {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DynamicThreadPoolWrapper messageCenterDynamicThreadPool;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ThreadPoolExecutor dynamicThreadPoolExecutor;
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
@SuppressWarnings("all")
|
|
|
|
|
public void runStateHandlerTest() {
|
|
|
|
|
log.info("Test thread pool runtime state interface, The rejection policy will be triggered after 30s...");
|
|
|
|
|
log.info("Test thread pool runtime state interface...");
|
|
|
|
|
|
|
|
|
|
// 启动动态线程池模拟运行任务
|
|
|
|
|
runTask(messageCenterDynamicThreadPool.getExecutor());
|
|
|
|
|
|
|
|
|
|
// 启动动态线程池模拟运行任务
|
|
|
|
|
runTask(dynamicThreadPoolExecutor);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runTask(ExecutorService executorService) {
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
ThreadUtil.sleep(5000);
|
|
|
|
|
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
|
|
|
|
try {
|
|
|
|
|
dynamicThreadPoolExecutor.execute(() -> {
|
|
|
|
|
log.info("Thread pool name :: {}, Executing incoming blocking...", Thread.currentThread().getName());
|
|
|
|
|
executorService.execute(() -> {
|
|
|
|
|
try {
|
|
|
|
|
int maxRandom = 10;
|
|
|
|
|
int temp = 2;
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
// Assignment thread pool completedTaskCount
|
|
|
|
|
if (random.nextInt(maxRandom) % temp == 0) {
|
|
|
|
|
Thread.sleep(10241024);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} else {
|
|
|
|
|
Thread.sleep(3000);
|
|
|
|
|
}
|
|
|
|
@ -51,7 +64,6 @@ public class RunStateHandlerTest {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info(" >>> Number of dynamic thread pool tasks executed :: {}", i);
|
|
|
|
|
ThreadUtil.sleep(500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|