File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Arvind Kini
Ranch Hand

Joined: Dec 28, 2000
Posts: 31

Please excuse me if this question has been discussed. tried doin a search but then cudnt help myself!
QUESTION : 27
Read the following snippet carefully
1. public synchronized void someMethod() {
2. //lots of code
3. try {
4. Thread.sleep(500);
5. } catch(InterruptedException e) {
6. //do some things here.
7. }
8. //more and more code here
9. }
Select all correct answers
a) code causes compilation error -sleep cannot be called in synchronised methods
b) thread sleeps for atleast 500 ms in this method if not interrupted
c) When the thread goes to sleep it releases lock on the object.
d) the sleeping thread alwayz have lock on the object.
ans given c,d
according to me it shud have been only b)
but then went thru khalid and it says c is right too
but how d) can be possible if c is true?
Please help
arv

Rob Acraman
Ranch Hand

Joined: Dec 03, 2000
Posts: 89
The API documentation for Thread.sleep states:
"The thread does not lose ownership of any monitors."
ie. it does not lose the lock.
Therefore, it seems to me that b and d are the correct answers.
What's the URL for the exam?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Arvind,
The correct answers are C and D.

Sorry folks ..typo .. should read B and D


<code>sleep()</code> does not give up the lock. See this discussion http://www.javaranch.com/ubb/Forum24/HTML/006002.html and answer by Ajith.
Hope that helps.
Jane
[This message has been edited by Jane Griscti (edited January 16, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Amit, Jhalani
Greenhorn

Joined: Jan 11, 2001
Posts: 21
When sleep() did'nt releases the lock then how come 'C' is the correct answer?
Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
Hello Arvind,

From whcih mock exam you got this question. Pls put up the link to that mock site and this question is ment for errata Forum.
Regards
Raj.


Regards,<P>Raj.<BR>-------------------------<BR>Afforts should be Appriciated.<BR>-------------------------
denish mehta
Ranch Hand

Joined: Dec 21, 2000
Posts: 135
how can u have the lock and not have it at the same time??
if both c & d are correct then won't we have a paradox??
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Sorry folks ...
Typo ... the correct answer should be B and D, not C and D.
Apologies for the confusion.

------------------

Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
Arvind Kini
Ranch Hand

Joined: Dec 28, 2000
Posts: 31
I am sorry guys, I donot rememebr the place from where I have taken this question . wud look out anyway .
So the confirmed ans is B and D.
Thankz to all
arv
 
 
subject: Threads