• Post Reply Bookmark Topic Watch Topic
  • New Topic

when a thread is in sleep...  RSS feed

 
krishna Gajarla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai all,

This is the question i faced in an interview.


when the thread is in sleep

ex if t.sleep(100) is there in your code

does it hold the monitor?

i said yes...is it true??
i need the correct explanation from any of you...

thanks in advance
rk
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sleep() has nothing to do with synchronisation. If the thread had the monitor before sleep(), it has it during sleep(). If it didn't have it before sleep(), it doesn't have it during sleep().

In contrast, wait() requires the thread to have the lock before wait(), and releases the lock while waiting.

A bartender will very shortly be complaining that your login name "kris" does not comply with the JavaRanch standards. To avoid that, go change it now.
 
krishna Gajarla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Peter...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!