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