Java Callable Future的简单应用



public static void main(String[] args) throws InterruptedException, Exception {
//创建单一线程池 

ExecutorService  threadPool = Executors.newSingleThreadExecutor();
Future<String> future =
threadPool.submit(new Callable<String>(){
public String call() throws Exception {
Thread.sleep(2000);
return "Hello";
}});
 
System.out.println("等待结果...");
System.out.println("拿到结果..."+future.get());
}


Android中 AsyncTask中有应用Callable...有兴趣的童鞋可以阅读一下源码!

你可能感兴趣的:(Java Callable Future的简单应用)