主线程中同步等待异步线程的返回
程序员文章站
2024-02-02 16:43:16
...
ExecutorService executor = Executors.newSingleThreadExecutor();
Future future = executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
return 100;
}
});
Object obj = future.get();
println(obj);
/**
* Waits if necessary for the computation to complete, and then
* retrieves its result.
future.get();
Future future = executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
return 100;
}
});
Object obj = future.get();
println(obj);
/**
* Waits if necessary for the computation to complete, and then
* retrieves its result.
future.get();
上一篇: jvm观察命令
下一篇: Java基础知识复习