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