Last active
November 18, 2020 11:43
-
-
Save alfredrichards/69f744f51ea1168cfa68bbef0080f1ce to your computer and use it in GitHub Desktop.
Java Future example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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