What is the difference between Thread.join and Synchronized?

Thread.join() waits for the thread to completely finish, whereas a synchronized block can be used to prevent two threads from executing the same piece of code at the same time.

It's hard to advise when to use one over the other in general, since they serve different purposes. It's rare to find an example, such as your code, where the difference between the two is minimal.

That being said, in your first example there is no guarantee the output will be alphabetical. You can't be sure which thread will get to the synchronized block first. So in this particular case, join() is most appropriate.


thread.join() stops the execution of current thread until the joined thread completes.. You have commented correctly.. :)

Synchronization prevents multiple threads from executing the synchronized part of code on the same instance.


The synchronized keyword enables a locking mechanism that allows threads to not step on each other. Java documentation describes this as a way to " preventing thread interference and memory consistency errors".

If you use join(), it makes sure that as soon as a thread calls join,the current thread(running thread) will not execute unless the thread you have called join is finished. I think the diagram below might help visualize this better.

enter image description here

Source