I am using the ExecutorService. I am opening 10 threads for a for-loop. So it opens 10 threads and when does the connection closes here? At executor.shutdown()? If yes, will it closes all 10 threads and open 10 threads again? Is there anything I can follow better coding standards in order to increase the performance here?
ExecutorService executor = Executors.newFixedThreadPool(10);
for(String str : stringList){
for(String str1 : stringList1){
for(String str2 : stringList2){
executor.execute(new Runnable() {
@Override
public void run() {
//do something
}
}
}
}
executor.shutdown();
executor.awaitTermination(24L, TimeUnit.HOURS);
Actually my idea is to iterate through the loop and save the data in a file and save it for every iteration. So I want to follow the best practices here as I don't want to see any server related issues like connection issues/outOfMemory exceptions in later stages. Please suggest.
I have implemented this by myself but I am a noob in multi-threading. So to get some clarification after seeing some other blogs and posts I have posted this. Please help!