Home > Back-end >  Why in the thread with the join () method?
Why in the thread with the join () method?

Time:09-21

In many cases, the main thread to generate and launched the child thread, need to use the child thread returned results, is also need the main thread
At the end of the child thread end again, this time using the join () method,
System. Out.println (Thread. CurrentThread (). The getName () + "Thread running start!" );
Thread6 thread1=new Thread6 ();
Thread1. Elegantly-named setName (" thread "B");
Thread1. The join ();
System. The out. Println (" then can thread1 execution after execution of the main thread ");

CodePudding user response:

The join () is the main function of synchronization, it can make the thread between parallel execution into serial execution
  • Related