Returning a value from a Thread?
问题 //... 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; Okay, I've looked all over. I need to know how I can make this wait until it finishes retrieving a value from a database to return this. 回答1: You use result.get() to wait for the task to finish and to retrieve the result. The API documentation is