修改动态线程池测试运行报警测试程序.

pull/10/head
chen.ma 3 years ago
parent 10833413db
commit 3150e9c581

@ -3,14 +3,12 @@ package cn.hippo4j.example.inittest;
import cn.hippo4j.example.constant.GlobalTestConstant; import cn.hippo4j.example.constant.GlobalTestConstant;
import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.starter.core.GlobalThreadPoolManage;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper;
import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* Test run time metrics. * Test run time metrics.
@ -27,32 +25,37 @@ public class RunStateHandlerTest {
public void runStateHandlerTest() { 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, The rejection policy will be triggered after 30s...");
ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor(); new Thread(() -> {
scheduledThreadPool.scheduleAtFixedRate(() -> { ThreadUtil.sleep(5000);
DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(GlobalTestConstant.MESSAGE_PRODUCE); for (int i = 0; i < Integer.MAX_VALUE; i++) {
ThreadPoolExecutor pool = poolWrapper.getPool(); DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(GlobalTestConstant.MESSAGE_PRODUCE);
try { ThreadPoolExecutor pool = poolWrapper.getPool();
pool.execute(() -> { try {
log.info("Thread pool name :: {}, Executing incoming blocking...", Thread.currentThread().getName()); pool.execute(() -> {
try { log.info("Thread pool name :: {}, Executing incoming blocking...", Thread.currentThread().getName());
int maxRandom = 10; try {
int temp = 2; int maxRandom = 10;
Random random = new Random(); int temp = 2;
// Assignment thread pool completedTaskCount Random random = new Random();
if (random.nextInt(maxRandom) % temp == 0) { // Assignment thread pool completedTaskCount
Thread.sleep(10241024); if (random.nextInt(maxRandom) % temp == 0) {
} else { Thread.sleep(10241024);
Thread.sleep(3000); } else {
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// ignore
} }
} catch (InterruptedException e) { });
// ignore } catch (Exception ex) {
} // ignore
}); }
} catch (Exception ex) {
// ignore log.info(" >>> Number of dynamic thread pool tasks executed :: {}", i);
ThreadUtil.sleep(500);
} }
}, 5, 2, TimeUnit.SECONDS); }).start();
} }
} }

Loading…
Cancel
Save