Bean范围请求的多线程问题

时间:2020-11-05 05:56:46

标签: java multithreading spring-boot java-8 parallel-processing

在将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应用程序中使用

0 个答案:

没有答案