package thread.learn;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* Created by liujinhong on 2017/3/6.
*/
public class CallableAndFuture {
static class MyThread implements Callable {
@Override
public String call() throws Exception {
return "Hello world";
}
}
static class MyThread2 implements Runnable {
@Override
public void run() {
}
}
public static void main(String[] args) {
ExecutorService threadPool = Executors.newSingleThreadExecutor();
Future future = threadPool.submit(new MyThread());
try {
System.out.println(future.get());
} catch (Exception e) {
} finally {
threadPool.shutdown();
}
}
}
from: https://www.cnblogs.com/liujinhong/p/6510667.html