Last active
July 19, 2020 20:30
-
-
Save abhi2495/239d9781fc7ac9d673d1e329ea2bd801 to your computer and use it in GitHub Desktop.
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
/* | |
################################################################################## | |
################################################################################## | |
######### IF YOU FOUND THIS GIST USEFUL, PLEASE LEAVE A STAR. THANKS. ############ | |
################################################################################## | |
################################################################################## | |
*/ | |
public void caller(){ | |
ExecutorService executorService = Executors.newFixedThreadPool(2); | |
Collection<Callable<Void>> callables = new ArrayList<>(); | |
callables.add(() -> doTask1()); | |
callables.add(() -> doTask2()); | |
try { | |
List<Future<Void>> taskFutureList = executorService.invokeAll(callables); | |
taskFutureList.get(0).get(); | |
taskFutureList.get(1).get(); | |
} catch (InterruptedException | ExecutionException e) { | |
//error | |
} | |
} | |
public Void doTask1() { | |
//some logic | |
return null; | |
} | |
public Void doTask2() { | |
//some logic | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment