File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuest Mock Exam Question

 
Bin Zhao
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
question:
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
Posts: 318
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you. I strongly believe d is incorrect. Did you copy and paste the answers?
Matt
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3663
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling sleep() does not release the lock. So the ans should be b and d.
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

[This message has been edited by Paul Anil (edited November 11, 2000).]
 
Bin Zhao
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Nijeesh.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic