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. - What truth? - That there is no spoon!!!
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
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.
Joined: Jul 21, 2003
"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 ]
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)
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.
Joined: Sep 14, 1999
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