在春節時淺橙的接口nginx上偶爾會報500的錯誤,但tomcat應用日志里找不到什么東西。后來想到有可能不是應用報的錯,而是在應用處理之前tomcat就報錯了,於是在spring boot中加上了tomcat的訪問日志。幾天后,發現了這個錯
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@4542552a rejected from java.util.concurrent.ThreadPoolExecutor@a3464b4[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 43433]
看起來是線程池的問題,而且是業務邏輯進入處理之前出的問題,業務邏輯的總入口是
* 淺橙請求我方api接口封裝
*
* @Description
*
* @author <a href="changjunhui8173@adpanshi.com">changjunhui</a>
* @param request
* @param httpRequest
* @return
*/
@RequestMapping(value = "/doCall")
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
value = "50000") })
@ResponseBody
public String doCall(HttpServletRequest httpRequest, @RequestParam String ua, @RequestParam String call,
@RequestParam() String args, @RequestParam String sign, @RequestParam(required = false) String timestamp) {
ResponseMessageQCApi response = new ResponseMessageQCApi(QianchengCode.SUCCESS);
// String call = "";
try {
// 淺橙請求我放接口傳入的參數
// Map<String, String> parameters = new HashMap<String, String>();
// Map<String, String[]> requestParams = httpRequest.getParameterMap();
//
// for (Iterator<String> iter = requestParams.keySet().iterator();
// iter.hasNext();) {
// String name = iter.next();
// String[] values = requestParams.get(name);
// String valueStr = "";
// for (int i = 0; i < values.length; i++) {
// valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr +
// values[i] + ",";
// }
后來在網上查到Hystrix是有個線程池的,而且默認的線程數就是10,於是把@HystrixCommand注釋掉,后來就沒有這個問題了。看來是因為正在處理的請求達到了最大線程數,來的新的請求就被拒絕掉了