Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created July 12, 2021 12:56
Show Gist options
  • Save wkdalsgh192/4f0a3a066d6862af2f46f5d60f550de3 to your computer and use it in GitHub Desktop.
Save wkdalsgh192/4f0a3a066d6862af2f46f5d60f550de3 to your computer and use it in GitHub Desktop.
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