When synchronizing the anon-static method method, if two threads competing to execute swim() for the same Test object, the first thread to enter the method will seize the lock of this Test object and will only release it when it finishes executing swim(). That means any other thread has to wait for the lock to be released to be able to enter swim(). But the trick in our program, that each thread is invoking swim() on a different Test object, so actually the two threads are not competing on the same object.
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |