1, Function: Call this method, the main process will stop here, waiting for the thread to finish before continuing to execute.
For example: Do not use join:
<?phpclass Join extends thread{public function run () { sleep (3); Echo __function__. Php_eol;} } $join = new Join (), $join->start (); Echo ' Just a test '. Php_eol;
Output:
Just a TestRun
Using join:
<?phpclass Join extends thread{public function run () { sleep (3); Echo __function__. Php_eol;} } $join = new Join (), $join->start (); $join->join (); Echo ' Just a test '. Php_eol;
Output:
Runjust a test
We can see that when using join, the last Echo statement needs to wait for the thread to finish running.
2. Why Join?
Think of a situation in which thread execution takes too long and the result is to be used in subsequent code to run the thread.
This allows us to use join to prevent the end of the mainline Cheng line enters upgradeable, or the subsequent code to run before the thread ends to get the results of the threading process.
3. Using join causes the process to block, which is not an end, but a performance. Join is not used to block threads.
4, Fork/join
Meaning of the Join method in multi-threading