posted 17 years ago
When answering questions about what multiple threads output, you cannot always rely on what happens when you run the program on your machine a few times.
Sometimes you might get the output you saw, but it isn't guaranteed.
The main point to notice in that program is that the synchronized keyword modifies an instance method in the class definition.
That means that when that method is executed, the object that is locked is the current instance of the class.
Since there are two different instances of the class, when one instance executes run(), it does not block the other instance from executing its run() method.