标签:ble tor pool exce 返回值 shutdown 通过 str exe
异步线程的实现接口Runnable是无法获得返回结果的,而另一个接口Callable可以返回结果。并通过如Future等方式来获取异步结果。
import java.util.concurrent.*; public class CallableDemo { public static void main(String[] args) throws ExecutionException, InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(1); Future<String> future = executorService.submit(() -> "return value"); System.out.println(future.get()); executorService.shutdown(); } }
输出结果
return value
标签:ble tor pool exce 返回值 shutdown 通过 str exe
原文地址:https://www.cnblogs.com/lay2017/p/10165942.html