devxlogo

Take Control of the Threads Created By a Program

Take Control of the Threads Created By a Program

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();

size=3>
This command will wait until the thread t1 has finished its work.

devx-admin

Share the Post: