• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Difference bet wait(milisec) and sleep(milisec)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They both did the same job.what actually makes them different at back end
 
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
Well, obviously, a Thread in a wait() can be notify() -ed
whereas a Thread in a sleep() can only be interrupted.
Also, a Thread in a wait() has released its lock on an object, whereas a Thread in a sleep() retains any locks it may have.
Bill

------------------
author of:
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Khalid Mughal book:
"- Waiting state:When in Running state , a thread can call the wait() method defined in Object [ !!! -V.K.] class to put itself unto the Waiting state. It must be notified by another thread, in order to move to the Ready - to- run state .
- Sleeping state: A call to the static method sleep() in the Thead (!!! - V.K.) class couses the current thread in Running state to transit to the Sleeping state. It wakes up after specified amount of time(...)
-Ready - to-run state: (...)In the Ready - to run state , a thread awaits its turn to get CPU time."
Those methods provides absolutely different functionality of threads. Sleep() makes thread to run with intevals, wait()[ and notify()] controls accessibility of synchronized methods of object for competing ( more then one) threads.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a thread on wait(xx) is notified (or timeout), it must seek lock first and then go to ready state. A thread on sleep(xx) goes to ready state immediately after interruption, or timeout. Wait(xx) is actually wait for an chance to get lock back.

hh
 
What a show! What atmosphere! What fun! What a tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic