This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQuest Mock Exam Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQuest Mock Exam Question" Watch "JQuest Mock Exam Question" New topic

JQuest Mock Exam Question

Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
I have a question about the fol from JQuest Mock Exam
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) //ignored
b)The Thread sleeps at least 500ms if not interrupted.
c) when thread go to sleep,it release the lock on the object.
d)The "sleeping" threads always have the lock on the object.
why the answer are c) and d)
I chose b) and c)
I think c) conflicts with d)
Can anyone explain this?
Thx in advance.

Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
I agree with you. I strongly believe d is incorrect. Did you copy and paste the answers?
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3592
Calling sleep() does not release the lock. So the ans should be b and d.
Get Certified, Guaranteed!
(Now Revised for the new Pattern)

[This message has been edited by Paul Anil (edited November 11, 2000).]

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
yes, answer c) and d) are absolutely identical to the meaning of the original test.
Can anyone throw more light on the effect of executing Thread.sleep() in a synchronized method on the lock of that thread holds?
Nijeesh Balan
Ranch Hand

Joined: Oct 09, 2000
Posts: 116
Hi Bin,
Even I feel that b and d are right answers...
B'cos I have read somewhere that sleep() doesn't release the lock on an object..

Thanks & Regards,<br />Nijeesh.
I agree. Here's the link:
subject: JQuest Mock Exam Question
It's not a secret anymore!