How to ensure all threads that started from main must end in order in which they started and main should end last? (I am new in learning thread in Java). Is there any builtin method
1 Answer
main can call Thread.join on the threads it explicitly starts.
Threads will end on their own accord. What would it mean to keep a thread alive if it was no longer running any code?
You might want each thread to keep running an event loop, checking each iteration (and waiting when idle) on a counter to see whether its number is up. But that would be weird.