Skip to content

Instantly share code, notes, and snippets.

@alfredrichards
Last active November 18, 2020 11:43
Show Gist options
  • Save alfredrichards/69f744f51ea1168cfa68bbef0080f1ce to your computer and use it in GitHub Desktop.
Save alfredrichards/69f744f51ea1168cfa68bbef0080f1ce to your computer and use it in GitHub Desktop.
Java Future example
ExecutorService executorService = Executors.newSingleThreadExecutor();
Runnable runnableTask = () -> System.out.println("This is a Runnable task");
Future<?> future1 = executorService.submit(runnableTask);
future1.wait();
Callable<String> callableTask = () -> "This is a Callable task";
Future<String> future2 = executorService.submit(callableTask);
String result = future2.get();
executorService.shutdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment