六号线晚报0523

天气:晴 风力:微风

callable

1.callable是一个可以带返回值的多线程接口,类似runnable,ruannable执行无返回值的run方法,callable执行有返回值的call方法

public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        CallClass call = new CallClass();
        ExecutorService es = Executors.newFixedThreadPool(1);
        Future f = es.submit(() -> {
            Thread.sleep(3000);
            System.out.println("call Hello");
            return "hello";
        });

        System.out.println(System.currentTimeMillis());
        if (f.isDone()) {
            System.out.println(f.get());
        }
        System.out.println(System.currentTimeMillis());
        System.out.println(f.get());
        System.out.println(System.currentTimeMillis());
        es.shutdown();
    }
}

你可能感兴趣的:(六号线晚报0523)