From 5bc468d08256154f2d78dd4dcee49b6157c46aee Mon Sep 17 00:00:00 2001 From: airoger Date: Sun, 28 Aug 2022 13:00:33 +0800 Subject: [PATCH] add example --- .../config/DynamicThreadPoolConfig.java | 36 +++++++++++++++++++ .../src/main/resources/application.properties | 8 ++--- .../src/main/resources/application.properties | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 hippo4j-example/hippo4j-spring-boot-starter-example/src/main/java/cn/hippo4j/example/server/config/DynamicThreadPoolConfig.java diff --git a/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/java/cn/hippo4j/example/server/config/DynamicThreadPoolConfig.java b/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/java/cn/hippo4j/example/server/config/DynamicThreadPoolConfig.java new file mode 100644 index 00000000..c2107332 --- /dev/null +++ b/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/java/cn/hippo4j/example/server/config/DynamicThreadPoolConfig.java @@ -0,0 +1,36 @@ +package cn.hippo4j.example.server.config; + +import cn.hippo4j.core.executor.DynamicThreadPool; +import cn.hippo4j.core.executor.support.ThreadPoolBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +public class DynamicThreadPoolConfig { + + @Bean(name = "messagePool") + @DynamicThreadPool + public ThreadPoolExecutor messageConsumerDynamicExecutor(){ + String poolId = "message-pool"; + ThreadPoolExecutor messagePool = ThreadPoolBuilder.builder() + .threadPoolId(poolId) + .threadFactory(poolId) + .dynamicPool() + .build(); + return messagePool; + } + + @Bean(name = "goodsPool") + @DynamicThreadPool + public ThreadPoolExecutor goodsDynamicExecutor(){ + String poolId = "goods-pool"; + ThreadPoolExecutor goodsPool = ThreadPoolBuilder.builder() + .threadPoolId(poolId) + .threadFactory(poolId) + .dynamicPool() + .build(); + return goodsPool; + } +} diff --git a/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/resources/application.properties b/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/resources/application.properties index 6647ba01..57a02d67 100644 --- a/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/resources/application.properties +++ b/hippo4j-example/hippo4j-spring-boot-starter-example/src/main/resources/application.properties @@ -6,15 +6,15 @@ management.metrics.export.prometheus.enabled=true management.server.port=29901 management.endpoints.web.exposure.include=* -spring.profiles.active=dev -spring.application.name=dynamic-threadpool-example +#spring.profiles.active=dev +spring.application.name=dynamic-demo spring.dynamic.thread-pool.server-addr=http://localhost:6691 ### Use netty to report thread pool monitoring data. The default is http. # spring.dynamic.thread-pool.report-type=netty # spring.dynamic.thread-pool.netty-server-port=8899 -spring.dynamic.thread-pool.namespace=prescription -spring.dynamic.thread-pool.item-id=dynamic-threadpool-example +spring.dynamic.thread-pool.namespace=yewei +spring.dynamic.thread-pool.item-id=dynamic-demo spring.dynamic.thread-pool.username=admin spring.dynamic.thread-pool.password=123456 diff --git a/hippo4j-server/src/main/resources/application.properties b/hippo4j-server/src/main/resources/application.properties index b8779e7c..cfa5fcdf 100644 --- a/hippo4j-server/src/main/resources/application.properties +++ b/hippo4j-server/src/main/resources/application.properties @@ -27,7 +27,7 @@ hippo4j.core.clean-history-data-enable=true ### Data source customization section spring.datasource.url=jdbc:mysql://localhost:3306/hippo4j_manager?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 spring.datasource.username=root -spring.datasource.password=root +spring.datasource.password=czzx201101136 ### Hikari Datasource spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver