Type a Callable, submit it, and call get()
Type a Callable, submit it, and call get()
Answer
ExecutorService pool = Executors.newFixedThreadPool(2); Future<String> f = pool.submit(() -> "result"); String value = f.get(); pool.shutdown();
submit() accepts both Runnable and Callable. When the generic is Callable<String>, get() returns String. Always shutdown() the pool when finished.