java - How do I ensure that all Threads are stopped before main Thread is stopped? -
This is my program in which a thread starts under the main method
public class Thread Test {Public Static Zero Key (String Algos []) throws Interrupted Expressions {Thread main thread = Thread WrenchTrad (); Thread t1 = new thread () {public runs zero () {while (true) {System.out.println ("hi"); }}}; // t1.setDaemon (true); T1.start (); }} How can I ensure that all the child threads will stop before the main thread is stopped?
I do not want to use the demon option Is it possible?
In the main thread, you can wait to end other threads.
In the method performed by the main thread (the main method in your example):
t1.join (); But remember that if t1 will not end, the main thread will not end. So you want to use Migrate with an expired time. t1.join (10000);
Comments
Post a Comment