(Thread) A.join() – causes current thread to wait for the thread A to complete.
I supposed then that calling this.join() from the run method will cause thread to deadlock – that it will wait for itself to complete. However it doesn’t happen – code compiles and runs just fine – without deadlock. What happens when I call this.join() then?
(Thread) A.join() – causes current thread to wait for the thread A to complete.
Share
The OP uses this.join() in the provided example
Nathan in his example uses Thread.currentThread().join() instead.
By using this.join() a new thread is created which is getting joined, but the main thread is intact.
@Nathan
The following works as intended: