主线程中同步等待异步线程的返回

阅读更多
ExecutorService executor = Executors.newSingleThreadExecutor();
Future future = executor.submit(new Callable() {

    @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();

你可能感兴趣的:(主线程中同步等待异步线程的返回)