Whenever a thread is created in a program, it is unknown when it will execute. This means there may be cases where the parent program has finished but the thread is still executing. One way to ensure that the main program exits only after the thread is finished with its work is by employing Joins. Join is a member function of the Java thread class.
Write this code at the end of the main thread:
t1.Join();
This command will wait until the thread t1 has finished its work.
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.























