Created
July 12, 2021 12:56
-
-
Save wkdalsgh192/4f0a3a066d6862af2f46f5d60f550de3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(); | |
Callable<String> hello = () -> { | |
Thread.sleep(2000L); | |
return "Hello"; | |
}; | |
Callable<String> java = () -> { | |
Thread.sleep(3000L); | |
return "Java"; | |
}; | |
Callable<String> minho = () -> { | |
Thread.sleep(1000L); | |
return "Minho"; | |
}; | |
List<Future<String>> futureList = executorService.invokeAll(Arrays.asList(hello,java,minho)); | |
futureList.stream().forEach((i) -> { | |
try { | |
System.out.println(i.get()); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} catch (ExecutionException e) { | |
e.printStackTrace(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment