I have initialized a exectuor service with N threads. After the N threads finishes i want to wait for a while and then reuse the executor with new instance of N threads. How do
Just not shut down your executor - reuse it instead. Generate a collection of Callable tasks instead of Runnable and use:
executor.invokeAll
It will execute all tasks and return as soon as all of them are done. If MrRunnable is not your class or for whatever reason it have to implements Runnable you can simply convert it to Callable like:
new Callable()
{
@Override
public Void call() throws Exception {
worker.run();
return null;
}
};