consider there is a program in which several threads are running.i want to modify the program in such a manner that when the main thread terminates all other threads have been terminated and i don't want to scan the file.Only i want to add some lines of code at the closing brace of main(like calling join on each of the live thread.)
Originally posted by Prahlad Joshi: the main method should be modified in such a manner that the main thread should be the last one to terminate.
That is a different question than what you originally asked and what Jan's answer is useful for.
If you want the JVM to continue running until all threads have finished, you don't have to change anything to your program, because that's already what happens if you run it as it is. Note that in that case the thread that runs the main() method exits, but the JVM doesn't stop running until all threads have stopped.
If you explicitly want the thread that runs the main() method to stop last, then you'll want to call join() on the other threads after starting them in the main() method. See the API documentation of class Thread for exact details of what join() does.