Thread methods - start, run, and join

In our example, we called start() because we wanted to execute the method in a separate thread and continue the execution of the current thread.

On the other hand, if we had invoked the join() method, the main thread would have been blocked until the new thread is terminated. Therefore, it would have caused the same "freezing" behavior that we wanted to avoid, even if we are using multiple threads.

Finally, the run() method is where the thread actually executes its callable target operation. We will override it when we extend the Thread class, as in the next recipe.

As a rule of thumb, always remember to call start() from the main thread to avoid blocking it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset