4月2号时发现内部框架在测试时会超时,检查流程计数器发现计数器有流程未减数,利用编译原理重写该计数类发现流程名字,调试得知在当时流程返回了null,导致future一直未完成,直到超时,问题已反馈给架构修复
异步框架代码比较乱在此整理
@Test
@DisplayName("记录CompletableFuture一个框架内的小问题")
void test3() {
CompletableFuture<String> future = new CompletableFuture();
future.complete(null);//流程中返回的响应null
future=future.thenCompose((s)-> {//s=null
if (true){//模拟问题发生
throw new NullPointerException();
}
return CompletableFuture.completedFuture(s);//不会执行
});
CompletableFuture.allOf(new CompletableFuture[]{future}).thenRunAsync(()->{
System.out.println("allThenRunAsync");//不会执行
});
}
总结
框架在生产中没有问题是因为,future一定要做timer超时处理,完成future,否则就会一直挂起.