|
|
|
@ -4,13 +4,18 @@ import cc.yunxi.common.domain.CommonResult;
|
|
|
|
|
import cc.yunxi.common.exception.BadRequestException;
|
|
|
|
|
import cc.yunxi.domain.query.TestQuery;
|
|
|
|
|
import cc.yunxi.enums.UserTypeEnum;
|
|
|
|
|
import cc.yunxi.service.ITestService;
|
|
|
|
|
import cn.hutool.log.Log;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.util.concurrent.ListenableFuture;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
@Api(tags = "测试接口")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/test")
|
|
|
|
@ -18,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class TestController {
|
|
|
|
|
|
|
|
|
|
private final ITestService testService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("测试接口成功")
|
|
|
|
|
@GetMapping("/test01")
|
|
|
|
|
public CommonResult<String> success() {
|
|
|
|
@ -48,4 +55,20 @@ public class TestController {
|
|
|
|
|
return CommonResult.success(testQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("测试异步调用")
|
|
|
|
|
@PostMapping("/test05")
|
|
|
|
|
public CommonResult<String> asyncCall() {
|
|
|
|
|
// testService.syncTest();
|
|
|
|
|
// testService.asyncTest();
|
|
|
|
|
// testService.asyncTestWithCustomExecutor();
|
|
|
|
|
ListenableFuture<String> future = testService.asyncTestResultWithCustomExecutor();
|
|
|
|
|
try {
|
|
|
|
|
String result = future.get();// 同步阻塞,获取线程执行结果
|
|
|
|
|
log.info("线程池处理成功,返回结果: {}", result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return CommonResult.success("数据处理完成");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|