Eduardo Mineo wrote:
When I was getting myself prepared to OCJP, I realized that confusion is the aim of the test.
Threads calling non-static synchronized methods in the same class will
only block each other if they're invoked using the same instance and if
they're called using two different instances, they get two locks, which do not interfere with each other.
Eduardo Mineo wrote:Hi Tom.
When I was getting myself prepared to OCJP, I realized that confusion is the aim of the test. So, get used to it
In fact, you must pay attention for all instance in play. Ever. But, in this case, pay even more attention to "static Dudes d". Only one instance of Dudes is in play, so you have two threads, represented by two instance of DudesChat making calls to only one instance of Dudes, created only one time on d = new Dudes().
Can you see the difference?
I see that both threads shares the same method on the same instance "new Dudes" which was instantiated only once cause it is static.
.. there are two threads with two different instances(new Chess()). Each instance has its own method run() and executes it and calls method move(). Threads don't share these methods with each other.
This code fragment has two threads but one instance(runnable). It executes the same method run() on the same instance. But run() method owns methods with different instances.
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Free, earth friendly heat - from the CodeRanch trailbosshttps://www.kickstarter.com/projects/paulwheaton/free-heat