Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Threads

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Threads and Synchronization forum for any further discussion.
reply
    Bookmark Topic Watch Topic
  • New Topic