This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MG2 #42 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MG2 #42" Watch "MG2 #42" New topic
Author

MG2 #42

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522

Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object.
4) Thread scheduling algorithms are platform dependent

the answer given is 2,3, 4.
I don't understand how the second stat. is true!!! lets say that the lock for object 'o' is taken by thread 'A', now thread 'B' wants to access object 'o'.... it can't. it should wait until 'A' releases the lock... right?


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Uma Balu
Ranch Hand

Joined: Aug 22, 2003
Posts: 61

lets say that the lock for object 'o' is taken by thread 'A', now thread 'B' wants to access object 'o'.... it can't. it should wait until 'A' releases the lock... right?

Yes... a thread can acquire a lock on a object, only if it is not locked by someother thread.... The statement "You can obtain a mutually exclusive lock on any object" might mean that the object need not be a Runnable object
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
Vicken:
The exact wording of the question might be important here. "You can obtain a lock on any object" is referring to you the programmer. In other words, the statement is about what is semantically possible, and yes, you can lock on any object.
If it said "a thread can lock...", then as you point out, it isn't so clear, but I would still interpret it the same way.


The Inner that is named is not the true Inner.
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522

"You can obtain a lock on any object" is referring to you the programmer. In other words, the statement is about what is semantically possible, and yes, you can lock on any object.

and how am i suppose to know if the question is refering to me as a programmer or me as a JVM compiler or even consider the semantics.?!!!
from my point of view, the statement is false, because the part "...on any object" refers clearly to objects whether they are locked or unlocked.
Does anybody agress with me?
[ September 17, 2003: Message edited by: Vicken Karaoghlanian ]
Mika Leino
Ranch Hand

Joined: Jan 07, 2002
Posts: 56
Vicken, I have to agree with Steve. The wording of that option in my view is talking about synchronization and locks in general, not whether a thread can obtain a particular lock at runtime.


Mika Leino<br />SCJP, SCWCD
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
I would agree with Steve too.
The point is that all objects in Java are candidate for locking.
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
Interesting commentry and I would agree there is some ambiguity. Good questions should go to the heart of the matter and not require nit picking or judgment about (the english) language, only about the Java language.
Marcus
(author of the question)


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
Would the real exam have questions that are unclearly worded?


SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Edward, i believe the questions in the exam will be very clear, you don't have to worry about questions from this type. i simply ignored this question, i suggest you do the same.
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
The people who put together the real questions put a great deal of effort in trying to ensure they are clear and unambiguous, and generally succeed. I have read a lot of feedback from people who have taken the real exam, and I rarely hear complaints about the wording of the questions.
I also try to make mine as clear as possible, which is why I monitor forums like this to see what people are saying and generally modify as a result of the feedback (though sometimes there is a delay whilst I think about it).
One of the benefits of my questions is that they have been on the web for a long time and the ambiguities and quirks have gradually been ironed out (though as you can see the odd one or two still exist). Writing good questions is not a trivial task.
Marcus
 
jQuery in Action, 2nd edition
 
subject: MG2 #42
 
Similar Threads
Threads
Marcus green's mock test
lock on method?
Object locks
Thread