• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MG2 #42

 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


"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 ]
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would agree with Steve too.
The point is that all objects in Java are candidate for locking.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would the real exam have questions that are unclearly worded?
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic