Skip to content

Commit

Permalink
optimize code and add spring @async test
Browse files Browse the repository at this point in the history
  • Loading branch information
KamToHung committed Oct 10, 2023
1 parent 7278058 commit 41b691e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class EagerThreadPoolExecutorProxy extends EagerThreadPoolExecutor implem
*/
private List<TaskWrapper> taskWrappers;

/**
* Reject handler type.
*/
private final String rejectHandlerType;

public EagerThreadPoolExecutorProxy(EagerThreadPoolExecutor executor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class ThreadPoolExecutorProxy extends ThreadPoolExecutor implements TaskE
*/
private List<TaskWrapper> taskWrappers;

/**
* Reject handler type.
*/
private final String rejectHandlerType;

public ThreadPoolExecutorProxy(ThreadPoolExecutor executor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href = "mailto:[email protected]">KamTo Hung</a>
*/
@Slf4j
@Service
public class TestService {

@Async("commonExecutor")
public void test() {
log.info("I am dynamic-tp-test-1 task");
}

}

0 comments on commit 41b691e

Please sign in to comment.