Simplified DynamicThreadPool usage (#757)

* Simplified DynamicThreadPool usage

* Simplified DynamicThreadPool usage
pull/759/head
weihubeats 2 years ago committed by GitHub
parent 04b79acfc1
commit e8485921bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.core.executor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Bean;
/**
*@author : wh
*@date : 2022/10/2 16:10
*@description:
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Bean
public @interface SpringDynamicThreadPool {
}

@ -19,10 +19,9 @@ package cn.hippo4j.example.config.etcd.config;
import java.util.concurrent.ThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.SpringDynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
@ -33,8 +32,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class ThreadPoolConfig {
@Bean
@DynamicThreadPool
@SpringDynamicThreadPool
public ThreadPoolExecutor messageConsumeDynamicExecutor() {
String threadPoolId = "message-consume";
return ThreadPoolBuilder.builderDynamicPoolById(threadPoolId);

@ -17,19 +17,19 @@
package cn.hippo4j.example.core.config;
import cn.hippo4j.core.executor.DynamicThreadPool;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import cn.hippo4j.core.executor.SpringDynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.example.core.handler.TaskTraceBuilderHandler;
import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
import com.alibaba.ttl.threadpool.TtlExecutors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.Constants.AVAILABLE_PROCESSORS;
import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_CONSUME;
import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_PRODUCE;
@ -41,8 +41,7 @@ import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_PRODUC
@Configuration
public class DynamicThreadPoolConfig {
@Bean
@DynamicThreadPool
@SpringDynamicThreadPool
public Executor messageConsumeTtlDynamicThreadPool() {
String threadPoolId = MESSAGE_CONSUME;
ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder()
@ -59,8 +58,7 @@ public class DynamicThreadPoolConfig {
return ttlExecutor;
}
@Bean
@DynamicThreadPool
@SpringDynamicThreadPool
public ThreadPoolExecutor messageProduceDynamicThreadPool() {
String threadPoolId = MESSAGE_PRODUCE;
ThreadPoolExecutor produceExecutor = ThreadPoolBuilder.builder()
@ -84,7 +82,7 @@ public class DynamicThreadPoolConfig {
* @return
*/
// @Bean
@DynamicThreadPool
@SpringDynamicThreadPool
public ThreadPoolTaskExecutor testSpringThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setThreadNamePrefix("test-spring-task-executor_");

Loading…
Cancel
Save