Page 1 of 1

About Question enthuware.ocpjp.v7.2.1558 :

Posted: Wed Jun 26, 2013 4:11 pm
by jklb
This is a beyond the actual exam question, but I was hoping you could provide some clarification: the line "synchronized(TestClass.class)" confused me - is it correct to say that this line has no effect because it only controls starting a thread and not what the thread's run() does?

Also, what would be the point of synchronizing on .class?

Thank you.

Re: About Question enthuware.ocpjp.v7.2.1558 :

Posted: Wed Jun 26, 2013 5:22 pm
by admin
1. Yes, this line does not effect the other thread that is started because of the call to .start().
2. You can synchronize on any object. .class is also an Object. So synchronizing on a .class object is no different from synchronizing on any other object. But the key is you need multiple threads to synchronize on the same object (no matter what object it is) if you want to access shared resource.

HTH,
Paul.