• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Threads

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When sleep() did'nt releases the lock then how come 'C' is the correct answer?
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic