java - Bean 范围请求的多线程问题
问题描述
Thread
目前在使用以下代码的并行流时面临问题
private ThreadPoolTaskExecutor executor
Future<List<Boolean>> resList = executor.submit(()->requestIds.parallelStream().map(id->completeTask(id)).collect(Collectors.toList()));
List<Boolean> resultList = resList.get();
无法使用获取范围请求的 bean/线程异常。流中使用的方法正在调用另一个类的另一个方法,这会为范围请求提供错误。
Error : java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
RequestContextListener
在 Spring Boot 应用程序中使用
解决方案
推荐阅读
- android - 为什么来自演示者的方法可以触发两次,因为来自回调的调用只有一次(EventBus)
- c - 在两个增量和间接运算符的情况下,C 如何处理操作优先级?
- r - 转换 R 中的格式(大量数据)
- go - golang结构中未定义
- r - 返回 Rstudio 中除子字符串外的所有内容的位置
- python - Django ManyToMany 关系 - 检查是否存在?
- php - 如何在 wordpress 中为多个用户角色创建单个表单
- python - 将计算列四舍五入为 1dp
- ruby-on-rails - 在每个月的第一个和第三个星期一在 ruby 中运行一个 rask 任务
- python - 如何分析烧瓶端点?