• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
pauleen pauleen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question was taken from jchq.net
Whats the correct answer for this and why.
Can anyone explain to me.

Which of the following keywords indicates a thread is releasing its Object lock?

1) release
2) wait
3) continue
4) notifyAll
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, well out of those four only "continue" is a keyword in the sense of being a reserved word in Java, but that's not the answer.

The correct answers are wait and notifyAll, which are methods on java.lang.Object. Check out the relevant sections of the Javadoc for Object. You may also find this page from the Threads section of Sun's Java Tutorial useful.

Welcome to JavaRanch!

Jules

P.S. You'll need to change your display name to comply with the policy (real-looking names only).
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is wait.

* release is not a Thread method.
* continue is a Java keyword. But it has nothing to deal with Thread.
* By calling notify(), it doesn't mean that the thread has given up its lock at the moment. The lock is only released when the thread has moved out of the synchronized code.
* By calling wait(), the thread gives up its lock on the object immediately.

This is a SCJP question. If you're now preparing for SCJP, I highly recommend the book Sun Certified Programmer & Developer for Java 2 Study Guide (Exam 310-035 & 310-027) by Kathy Sierra and Bert Bates.

Joyce
[ September 05, 2004: Message edited by: Joyce Lee ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, Joyce is right. Subtle point about notifyAll(); it's typically the last thing you do in a synchronized block. Probably why I only scored 80% on my SCJP!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Threads and Synchronization forum for any further discussion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic