Web项目,Java后台使用多线程查询结果后要怎么把查出来的结果返回给前端?已经异步了
FutureTask<Boolean> future = new FutureTask<>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
System.out.println("call");
Thread.sleep(5000);
return true;
}
});
System.out.println("main");
Executors.newCachedThreadPool().submit(future);
future.get();
System.out.println("main1");
主线程等待异步结果一并返回;
或者WebSocket直接甩
有返回值的 可以试用java8的并行流的操作返回