About Question enthuware.ocpjp.v7.2.1558 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jklb
Posts: 17
Joined: Tue Dec 18, 2012 7:54 pm
Contact:

About Question enthuware.ocpjp.v7.2.1558 :

Post 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.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 229 guests