File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

pauleen pauleen
Greenhorn

Joined: Aug 31, 2004
Posts: 3
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

Joined: Aug 02, 2004
Posts: 823
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

Joined: Jul 11, 2003
Posts: 1392
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

Joined: Aug 02, 2004
Posts: 823
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

Moving to Threads and Synchronization forum for any further discussion.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads