Ruben Soto wrote:
Jelle Klap wrote:If I told you that System.out is a static final reference to a PrintStream instance, and that a PrintStream's print() method uses a synchronized block that synchronizes on its intrinsic lock (using the this reference), could you then explain this behavior?
I understand what you are saying, but the statement marked as bold is not relevant for this example, correct?
Well, yes and no.
It's important to understand that the output of both run() methods will never intertwine, because both run() methods synchronize on the same lock i.e. System.out's intrinsic lock.
It's also important to understand that, although the print() method
also synchronizes on this lock, this is not a dead-lock scenario, because intrinsic locks are reentrant.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.