I need main thread to wait until all the thread pools task complete. How to do it? For eg: I have program:
public static void main(String[] args){
ExecutorService executor = Executors.newFixedThreadPool(2);
Map<String,String> test = new HashMap<String,String>(){{
put("a","b");
put("c","b");
}};
for(String t: test.keySet()) {
executor.execute(new Runnable() {
public void run() {
for(int i=0;i<100;i++){
System.out.println("t = " + t);
}
}
})
;
}
executor.shutdown();
System.out.println("outside");;
}
In the above code, I want to print "outside" always at the last i.e. after completion of ExecutorService tasks.