Example of adding thread pool automatic registration function

pull/494/head
chen.ma 2 years ago
parent ef93ab435d
commit 5251d0a82c

@ -22,7 +22,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableDynamicThreadPool
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.core")
@SpringBootApplication(scanBasePackages = {"cn.hippo4j.example.core", "cn.hippo4j.example.server"})
public class Hippo4JServerExampleApplication {
public static void main(String[] args) {

@ -0,0 +1,49 @@
package cn.hippo4j.example.server;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterParameter;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.core.executor.support.DynamicThreadPoolService;
import lombok.AllArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Register dynamic thread-pool test
*/
@Component
@AllArgsConstructor
public class RegisterDynamicThreadPoolTest implements ApplicationRunner {
private final DynamicThreadPoolService dynamicThreadPoolService;
@Override
public void run(ApplicationArguments args) throws Exception {
String threadPoolId = "register-dynamic-thread-pool";
DynamicThreadPoolRegisterParameter parameterInfo = new DynamicThreadPoolRegisterParameter();
parameterInfo.setThreadPoolId(threadPoolId);
parameterInfo.setCorePoolSize(2);
parameterInfo.setMaximumPoolSize(14);
parameterInfo.setQueueType(9);
parameterInfo.setCapacity(110);
parameterInfo.setKeepAliveTime(110);
parameterInfo.setRejectedType(2);
parameterInfo.setIsAlarm(0);
parameterInfo.setCapacityAlarm(90);
parameterInfo.setLivenessAlarm(90);
parameterInfo.setAllowCoreThreadTimeOut(0);
ThreadPoolExecutor threadPoolExecutor = ThreadPoolBuilder.builder()
.threadPoolId(threadPoolId)
.threadFactory(threadPoolId)
.dynamicPool()
.build();
DynamicThreadPoolRegisterWrapper registerWrapper = DynamicThreadPoolRegisterWrapper.builder()
.dynamicThreadPoolRegisterParameter(parameterInfo)
.dynamicThreadPoolExecutor(threadPoolExecutor)
.build();
dynamicThreadPoolService.registerDynamicThreadPool(registerWrapper);
}
}
Loading…
Cancel
Save