使用Spring的WebAsyncTask异步请求时出错Can't set AsyncWebRequest with concurrent handling in progress
来源:互联网 发布:大数据毕业设计 编辑:程序博客网 时间:2024/06/05 14:29
使用Spring的WebAsyncTask异步请求时出现如下错误:
java.lang.IllegalStateException: Cannot forward after response has been committedjava.lang.IllegalStateException: Can't set AsyncWebRequest with concurrent handling in progressorg.springframework.web.util.NestedServletException: Request processing failed; Caused by: java.lang.IllegalStateException: Can't set AsyncWebRequest with concurrent handling in progress at org.springframework.util.Assert.state(Assert.java:392) at org.springframework.web.context.request.async.WebAsyncManager.setAsyncWebRequest(WebAsyncManager.java:108)
表面上看错误描述并不清楚。这里我仅仅记录我的解决方法,我这里是因为时间超时引起的。也许你也是这样的情况:
原代码结结构如下:
@RequestMapping(value = { "/webAsyncTask/test" }) public WebAsyncTask test(HttpServletRequest request) { Callable<String> callable = new Callable<String>() { public String call() throws InterruptedException { String string = new String(); Thread.sleep(15000); return string; } }; return new WebAsyncTask(callable); }
这里直接返回的new WebAsyncTask(callable)报错。我是通过设置超时时间解决的:返回new WebAsyncTask(60000, callable);
注意:即使设置里超时时间而没做超时处理,这样是不严谨的。因为当60000毫秒之后call()没执行完依然会报异常。Spring对超时处理提供有WebAsyncTask.onTimeout()方法。
所有我最终的代码结构如下:
@RequestMapping(value = { "/webAsyncTask/test" }) public WebAsyncTask test(HttpServletRequest request) { Callable<String> callable = new Callable<String>() { public String call() throws InterruptedException { String string = new String(); Thread.sleep(15000); return string; } }; WebAsyncTask asyncTask = new WebAsyncTask(60000, callable); asyncTask.onTimeout(new Callable<String>() { public String call() throws Exception { String string = "请求超时!"; return string; } }); return asyncTask; }
0 0
- 使用Spring的WebAsyncTask异步请求时出错Can't set AsyncWebRequest with concurrent handling in progress
- spring mvc使用MultiActionController时发生No request handling method with name的错误
- internet can't access the oralce server set up in the intranet with firewall(总结自IT_PUB)
- can't resolve host-使用GIT 请求远程仓库时出现的问题以及解决办法
- goagent can't set attribute 的解决办法
- error at ::0 can't find referenced pointcut.spring的出错原因
- [MySQL 工具] pt-query-digest使用出错问题分析Can't locate Time/HiRes.pm in @INC
- RESTful Error Handling with Spring
- 使用TortoiseSVN时出错: Can't use Subversion command line client: svn...
- Exception Handling in Spring MVC
- Exception Handling in Spring MVC
- Exception Handling in Spring MVC
- spring boot--使用异步请求,提高系统的吞吐量
- Concurrent Set的创建
- GreenDao报Can't replace method in ...\mvp\model\BrandModel.java:120 with generated version.错误的解决办法
- \t\t当异步请求与Silverlight相遇时,彼此通信问题的解决办法
- 在局域网内启动节点时的“Can't set long node name”异常
- goagent 上传时取消 两步验证仍出现AttributeError: can't set attribute的解决方法
- windows系统下mysql修改默认字符编码
- C++入门基础
- 函数、数组
- CentOs 安装tomcat7
- iOS之imageView的图片不变形,居中
- 使用Spring的WebAsyncTask异步请求时出错Can't set AsyncWebRequest with concurrent handling in progress
- 最新版SDWebImage的使用
- WordPress主题 wpdx 响应式CMS/Blog 开源无限制版本含用户中心主题[v3.5版]
- android基础知识---重写系统Crash处理类保存上传和完美退出程序的方法
- MySQL之外键约束
- springboot 定时任务
- 『 推荐算法』笔记一:什么是推荐系统
- 配置Tengine服务器
- ramdisk.img文件解析