I am using threads in java to read file and print certain items to console. I am reading more than 5 files in a loop, and at the end of the loop I want to print a message.
So:
for (int i = 1; i < args.length; i++){
String filename = args[i]; //this will contain each filename
// your code goes here
new processFile(filename,counter).start();
}
System.out.print(counter.numerOfMatches)
I looked for solution online but almost all suggests using join(). Does that not defeat the purpose of using threads. Is there not a way to run all of the fileProcessing threads parallelly without one having to wait for the another and then somehow figure out when all of the processes finishes before moving to the final line?