i reckon join is used to when one thread waits for another to finish and then the former thread continues.
say if i hav created 3 child threads out of my main thread . i give 3 join methods in my main so that it waits till all 3 child threads finish their task and then the main thread resumes.
what i want to ask is even if i dont give join on the 3 threads inside main and finish main even before the 3 threads finish i dont find the other 3 threads getting interrupted. shouldnt the 3 child threads which were churned out of main get interupted when the main method ends. i mean that is what join method is used for
No! That's the whole point of threads, they are independant threads of control. They have no relationship with the main thread, so they can continue to run on their own after the main thread dies. Now, there is the concept of a daemon thread. You can set a thread to be a daemon thread before you start it. When a thread is a daemon thread, it will continue to run until there are no more user threads running. At that point, the JVM will quit. Another way to state it is that, the JVM continues to run only as long as there are user threads running. In your example, you could test this out by making each of the 3 threads you spawn a daemon thread, and making them all run infinate loops. Then let the main thread quit. When it does, you will see the whole JVM quits, even though the other 3 threads were still active.