测试用例换一种方式注入动态线程池.

pull/20/head
chen.ma 3 years ago
parent ccd9ff16e0
commit f42ab65a20

@ -1,12 +1,10 @@
package cn.hippo4j.example.inittest; 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 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 javax.annotation.Resource;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -20,6 +18,9 @@ import java.util.concurrent.ThreadPoolExecutor;
@Component @Component
public class RunStateHandlerTest { public class RunStateHandlerTest {
@Resource
private ThreadPoolExecutor dynamicThreadPoolExecutor;
// @PostConstruct // @PostConstruct
@SuppressWarnings("all") @SuppressWarnings("all")
public void runStateHandlerTest() { public void runStateHandlerTest() {
@ -28,10 +29,8 @@ public class RunStateHandlerTest {
new Thread(() -> { new Thread(() -> {
ThreadUtil.sleep(5000); ThreadUtil.sleep(5000);
for (int i = 0; i < Integer.MAX_VALUE; i++) { for (int i = 0; i < Integer.MAX_VALUE; i++) {
DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(GlobalTestConstant.MESSAGE_PRODUCE);
ThreadPoolExecutor pool = poolWrapper.getExecutor();
try { try {
pool.execute(() -> { dynamicThreadPoolExecutor.execute(() -> {
log.info("Thread pool name :: {}, Executing incoming blocking...", Thread.currentThread().getName()); log.info("Thread pool name :: {}, Executing incoming blocking...", Thread.currentThread().getName());
try { try {
int maxRandom = 10; int maxRandom = 10;

Loading…
Cancel
Save