go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  sleep() vs wait() -- code examples
 
Subject: sleep() vs wait() -- code examples
Author: EricJ
Posted on: 02/25/2007 04:09:38 AM

The differences between sleep() and wait() are:

  • sleep() is a method of class Thread and wait() is a method of class Object;
  • The code sleep(1000) puts the running thread aside for exactly one second. The code wait(1000) cause the running thread wait for notification for up to one second. In other words, the thread can be awakened at any time less than one second;
  • sleep() withhold the monitor while relinquishing its CPU time slot and wait() release all the rights: monitor and time slot. If sleep() is, by accident, put into a synchronized block (which means only one thread can get the monitor and run into the block at a time), it would prevent all other threads from grabbing the monitor and block all the process.


    Replies:


    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.