posted 12 years ago
In both example programs that is purely coincidental; the order is not predictable.
It's also possible for thread 2 to complete invocations of method 1 and 2 before thread 1 gets its turn.
Adding the keyword synchronized to a method only ensures that no two threads can execute that method (or any other body of code that synchonizes on the same lock) concurrently.
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.