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.
That is what executor.shutdown(); does. If you want to shutdown immediately you need to use shutdownNow()