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.
About Question enthuware.ocpjp.v7.2.1558 :
Moderator: admin
-
- Posts: 17
- Joined: Tue Dec 18, 2012 7:54 pm
- Contact:
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1558 :
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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 219 guests