This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes when a thread is in sleep... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "when a thread is in sleep..." Watch "when a thread is in sleep..." New topic
Author

when a thread is in sleep...

krishna Gajarla
Greenhorn

Joined: Oct 02, 2005
Posts: 21
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


Thanks and Regards,<br />krishna<br />------------------<br />Charles Darwin: <br />"It is not the strongest of the species that survives, <br />nor the most intelligent, <br />but the one most responsive to change"
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
krishna Gajarla
Greenhorn

Joined: Oct 02, 2005
Posts: 21
Thank you Peter...
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: when a thread is in sleep...
 
Similar Threads
Question on sleep() method from dan's
The java desktop application if hang up when not using for a period of time (about 30 minutes)
threads not misbehaving in 1.5
wait, yield, sleep
Having a time gap between 2 async method calls