From 41b691e15938057f08654914155b543108863bda Mon Sep 17 00:00:00 2001 From: KamToHung Date: Wed, 11 Oct 2023 00:27:49 +0800 Subject: [PATCH] optimize code and add spring @Async test --- .../apache/EagerThreadPoolExecutorProxy.java | 3 +++ .../core/support/ThreadPoolExecutorProxy.java | 3 +++ .../example/ZookeeperExampleApplication.java | 2 ++ .../example/controller/TestController.java | 11 +++++++++++ .../example/service/TestService.java | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java diff --git a/adapter/adapter-dubbo/src/main/java/org/dromara/dynamictp/adapter/dubbo/apache/EagerThreadPoolExecutorProxy.java b/adapter/adapter-dubbo/src/main/java/org/dromara/dynamictp/adapter/dubbo/apache/EagerThreadPoolExecutorProxy.java index 4d53b6ec1..266529ede 100644 --- a/adapter/adapter-dubbo/src/main/java/org/dromara/dynamictp/adapter/dubbo/apache/EagerThreadPoolExecutorProxy.java +++ b/adapter/adapter-dubbo/src/main/java/org/dromara/dynamictp/adapter/dubbo/apache/EagerThreadPoolExecutorProxy.java @@ -41,6 +41,9 @@ public class EagerThreadPoolExecutorProxy extends EagerThreadPoolExecutor implem */ private List taskWrappers; + /** + * Reject handler type. + */ private final String rejectHandlerType; public EagerThreadPoolExecutorProxy(EagerThreadPoolExecutor executor) { diff --git a/core/src/main/java/org/dromara/dynamictp/core/support/ThreadPoolExecutorProxy.java b/core/src/main/java/org/dromara/dynamictp/core/support/ThreadPoolExecutorProxy.java index ad44dd4f3..7c255ecaa 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/support/ThreadPoolExecutorProxy.java +++ b/core/src/main/java/org/dromara/dynamictp/core/support/ThreadPoolExecutorProxy.java @@ -42,6 +42,9 @@ public class ThreadPoolExecutorProxy extends ThreadPoolExecutor implements TaskE */ private List taskWrappers; + /** + * Reject handler type. + */ private final String rejectHandlerType; public ThreadPoolExecutorProxy(ThreadPoolExecutor executor) { diff --git a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/ZookeeperExampleApplication.java b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/ZookeeperExampleApplication.java index 06fd4d60a..7d5b6bda2 100644 --- a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/ZookeeperExampleApplication.java +++ b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/ZookeeperExampleApplication.java @@ -20,11 +20,13 @@ import org.dromara.dynamictp.core.spring.EnableDynamicTp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; /** * @author Redick01 */ @EnableDynamicTp +@EnableAsync @SpringBootApplication public class ZookeeperExampleApplication { diff --git a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/controller/TestController.java b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/controller/TestController.java index 98d48f0ae..395938827 100644 --- a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/controller/TestController.java +++ b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/controller/TestController.java @@ -20,6 +20,7 @@ import org.dromara.dynamictp.core.DtpRegistry; import org.dromara.dynamictp.core.support.task.runnable.NamedRunnable; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.example.service.TestService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -38,6 +39,16 @@ public class TestController { @Resource private ThreadPoolExecutor dtpExecutor1; + @Resource + private TestService testService; + + + @GetMapping("/dtp-zookeeper-example/testAsync") + public String testAsync() throws InterruptedException { + testService.test(); + return "success"; + } + @GetMapping("/dtp-zookeeper-example/test") public String test() throws InterruptedException { task(); diff --git a/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java new file mode 100644 index 000000000..8c073bd2a --- /dev/null +++ b/example/example-zookeeper/src/main/java/org/dromara/dynamictp/example/service/TestService.java @@ -0,0 +1,19 @@ +package org.dromara.dynamictp.example.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +/** + * @author KamTo Hung + */ +@Slf4j +@Service +public class TestService { + + @Async("commonExecutor") + public void test() { + log.info("I am dynamic-tp-test-1 task"); + } + +}