我在Tomcat 8.5上部署了一个Spring MVC Web应用程序,其中包含以下控制器:
import java.util.concurrent.Callable;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class AppController {
@RequestMapping(value="getOkSync", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String getOkSync() {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "ok";
}
@RequestMapping(value="getOkAsync", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Callable<String> getOkAsync() {
return new Callable<String>() {
@Override
public String call() {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "ok";
}
};
}
}
第一种方法在60秒后返回正确结果,而第二种方法在大约30秒后返回HTTP响应代码500和相应的Spring类日志
Could not complete async processing due to timeout or network error.
如果将延迟设置为20秒,则两种方法在20秒后都如预期地返回“ok”。
超时是由Spring MVC还是Tomcat控制的?哪个属性控制超时?