解决接口响应超时

This commit is contained in:
2025-05-08 19:02:44 +08:00
parent 4abfc570a0
commit 4a6cca7373
9 changed files with 137 additions and 5 deletions

View File

@ -6,10 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.annotation.Timeout;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.constant.SystemConstant;
import com.greenorange.promotion.constant.UserConstant;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
@ -24,14 +24,11 @@ import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.user.UserInfoService;
import com.greenorange.promotion.service.user.UserMainInfoService;
import com.greenorange.promotion.utils.JWTUtils;
import com.greenorange.promotion.utils.RegexUtils;
import com.greenorange.promotion.utils.SendSmsUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
@ -408,4 +405,16 @@ public class UserInfoController {
}
@PostMapping("/test")
@Timeout(5000) // 设置超时时间为 3000 毫秒3秒
public String testMethod() throws InterruptedException {
// 模拟长时间的任务,超过 3 秒会抛出超时异常
Thread.sleep(10000); // 模拟 5 秒的耗时操作
return "任务完成";
}
}