|
|
|
@ -23,36 +23,37 @@ import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterCoreNoti
|
|
|
|
|
import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterServerNotifyParameter;
|
|
|
|
|
import cn.hippo4j.common.toolkit.JSONUtil;
|
|
|
|
|
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
|
|
|
|
|
import cn.hippo4j.core.executor.support.QueueTypeEnum;
|
|
|
|
|
import cn.hippo4j.core.executor.support.RejectedTypeEnum;
|
|
|
|
|
import cn.hippo4j.message.enums.NotifyPlatformEnum;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register dynamic thread-pool test.
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
public class RegisterDynamicThreadPoolTest {
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void registerDynamicThreadPool() {
|
|
|
|
|
String threadPoolId = "register-dynamic-thread-pool";
|
|
|
|
|
DynamicThreadPoolRegisterParameter parameterInfo = new DynamicThreadPoolRegisterParameter();
|
|
|
|
|
parameterInfo.setThreadPoolId(threadPoolId);
|
|
|
|
|
parameterInfo.setThreadNamePrefix(threadPoolId);
|
|
|
|
|
parameterInfo.setCorePoolSize(3);
|
|
|
|
|
parameterInfo.setMaximumPoolSize(14);
|
|
|
|
|
parameterInfo.setQueueType(9);
|
|
|
|
|
parameterInfo.setCapacity(110);
|
|
|
|
|
parameterInfo.setKeepAliveTime(110L);
|
|
|
|
|
parameterInfo.setRejectedType(2);
|
|
|
|
|
parameterInfo.setIsAlarm(0);
|
|
|
|
|
parameterInfo.setCapacityAlarm(90);
|
|
|
|
|
parameterInfo.setActiveAlarm(90);
|
|
|
|
|
parameterInfo.setAllowCoreThreadTimeOut(Boolean.TRUE);
|
|
|
|
|
public static ThreadPoolExecutor registerDynamicThreadPool(String threadPoolId) {
|
|
|
|
|
DynamicThreadPoolRegisterParameter parameterInfo = DynamicThreadPoolRegisterParameter.builder()
|
|
|
|
|
.corePoolSize(3)
|
|
|
|
|
.maximumPoolSize(10)
|
|
|
|
|
.queueType(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE.type)
|
|
|
|
|
.capacity(110)
|
|
|
|
|
// TimeUnit.SECONDS
|
|
|
|
|
.keepAliveTime(100L)
|
|
|
|
|
// TimeUnit.MILLISECONDS
|
|
|
|
|
.executeTimeOut(800L)
|
|
|
|
|
.rejectedType(RejectedTypeEnum.ABORT_POLICY.type)
|
|
|
|
|
.isAlarm(true)
|
|
|
|
|
.capacityAlarm(80)
|
|
|
|
|
.activeAlarm(80)
|
|
|
|
|
.threadPoolId(threadPoolId)
|
|
|
|
|
.threadNamePrefix(threadPoolId)
|
|
|
|
|
.allowCoreThreadTimeOut(true)
|
|
|
|
|
.build();
|
|
|
|
|
// Core mode and server mode, you can choose one of them.
|
|
|
|
|
DynamicThreadPoolRegisterCoreNotifyParameter coreNotifyParameter = DynamicThreadPoolRegisterCoreNotifyParameter.builder()
|
|
|
|
|
.activeAlarm(80)
|
|
|
|
@ -74,5 +75,6 @@ public class RegisterDynamicThreadPoolTest {
|
|
|
|
|
.build();
|
|
|
|
|
ThreadPoolExecutor dynamicThreadPool = GlobalThreadPoolManage.dynamicRegister(registerWrapper);
|
|
|
|
|
log.info("Dynamic registration thread pool parameter details: {}", JSONUtil.toJSONString(dynamicThreadPool));
|
|
|
|
|
return dynamicThreadPool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|