Here is my code snippet.
ExecutorService executor = Executors.newFixedThreadPool(ThreadPoolSize);
while(conditionTrue)
{
ClassImplementingRunnable c = new ClassImplementingRunnable();
executor.submit(c);
}
Now after this is do
executor.shutdown();
What i want to achieve here is that i want to wait for all the threads in the threadpool to have finished the execution and then i want to shutdown the executor.
But i guess this is not what is happening here. The main thread seems to be executing shutdown and it just shuts down everything.
Before when my threadpool size was 2, i did the following and it seemed to work.
ClassImplementingRunnable c1 = new ClassImplementingRunnable();
executor.submit(c1);
ClassImplementingRunnable c2 = new ClassImplementingRunnable();
executor.submit(c2);
Future f1 = executor.submit(c1);
Future f2 = executor.submit(c2);
while(!f1.done || !f2.done)
{}
executor.submit();
How do i do this for a greater number of threads in the threadpool? Thanks.