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

does sleep() and yield() release the lock?

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was checking out the threads in the threading section of the saloon .and noticed in a thread the sleep() and yield don't give up the lock? is it true.pls check out the thread started by steve brown (Thread starve! shouldn't yield or wait/notify help?)
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that is correct.
Threads do not loose their monitors when they are yield() or sleep()
I do know that when they made to wait(),they had to give up their monitor of the object, since wait() and giving up lock is
one atomic unit
Ragu
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I read from some book saying that yield() would give up both the lock and monitor time. So how it don't lose the monitor?
I'm puzzled
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sleep() does not release the monitor.
But yield() does.
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Lee
--------------
sleep() does not release the monitor.
But yield() does.
-------------
tvs
Sun Certified Programmer for Java2 Platform
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most emphatically NO! Tch!
A call to yield does not release a lock on a synchronized object. Yield is a static method in Thread which gives the thread scheduler the chance to execute another Thread.
Only wait - 3 different wait methods in Object - releases the monitor and puts the executing Thread in a special state.
Bill
------------------
author of:
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Most emphatically NO! Tch!
A call to yield does not release a lock on a synchronized object. Yield is a static method in Thread which gives the thread scheduler the chance to execute another Thread.
Only wait - 3 different wait methods in Object - releases the monitor and puts the executing Thread in a special state.
Bill


Thankyou very much Bill
Ragu
 
reply
    Bookmark Topic Watch Topic
  • New Topic