问题遇到的现象和发生背景
如下代码中,多线程处理业务,doSomeThing方法中会调用其他服务的feign方法,有一定的几率出现invalidte token : ***
问题相关代码,请勿粘贴截图
//获取原线程的请求参数
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
// 异步处理各种情况
List<CompletableFuture<AsyncResult>> futureList = orderList
.stream()
.map(order->
CompletableFuture.supplyAsync(()->{
//设置请求原线程下的参数
RequestContextHolder.setRequestAttributes(attributes,true);
return this.doSomeThing(order);
},orderEditThreadPool))
.collect(Collectors.toList());
CompletableFuture<Void> allCF = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
allCF.join();
请问为什么会出现这种情况,主要是想知道原因,不是想知道解决方案。