• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sleep method in threads  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Before I start, my condolences to Phil Maquet's family. My sincere
sympathies to his family. May his sould rest in peace.

I do not know whether this should appear in the intermediate or beginner
section. My question is -
What is the importance of the sleep method? or
Under what circumstances I should use the sleep method ?

The only answer I can think of is time slicing. Please let me have your
comments.

Regards,

Caesar
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of the time, I use "sleep()" during debugging, to slow something down so I can look at it on the screen! But otherwise, I think it's most often used in graphics and animation; for example, you might paint the screen, sleep for 50 milliseconds, and paint again.
 
Caesar Dutta
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest. But is it ok to think that "Sleep method may be used
for time slicing".

I do not write much client side program dealing with GUI. I am more on the
server side. But still if I am asked such a question "What is the
importance of sleep method, or when will you use it" what should I say ?.

Frank and honest answer would be - "I never came across a situation to
use it".

Regards,

Caesar
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Caesar Dutta:
Thanks Ernest. But is it ok to think that "Sleep method may be used
for time slicing".


You could use it that way, but a better way to make threads cooperate and share resources is using wait() and notify(). Using sleep() is somewhat crude in comparison.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!