//... Some annoying getter
ExecutorService es = Executors.newSingleThreadExecutor();
Future<Integer> result = es.submit(new Callable<Integer>() {
public Integer call() throws Exception {
//Get some value from the SQL database.
}
});
return result;
好的,我已经看遍了。我需要知道如何让它等到它完成从数据库中检索值以返回此值。
您可以使用
result.get()
等待任务完成并检索结果。
API 文档是您的朋友。这是描述Future
API 的页面。