• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use sleep ?.  RSS feed

 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to put some delay before showing the output (without the concept of threads). Can anyone please tell me ?. Do we have any function like delay or something which solve my purpose ?.


Thanks in advance.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer Timer and TimerTask class.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are always using at least one Thread. Your program runs in the main Thread . You can access the current Thread trough

and send this one to sleep().


Pascal
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



bye for now
sat
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pascal betz posted November 21, 2006 03:46 AM
You can access the current Thread trough

Thread.currentThread()

and send this one to sleep().



Nope.
sleep is static and you can ONLY set the current thread to sleep. Not any thread that you specify.


Yours,
Bu.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Burkhard: You'r right it is static and it should be called on the class instead of the instance. Ahhhhh.

Still


will put the current Thread to sleep :-). It is just not good programming/coding and confusing.

Pascal
 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, by Thread.currentThread() my purpose is fullfilled.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as Burkhard said:
Do not call Thread.currentThread().sleep().
Use Thread.sleep().

Sleep is a static method and should be called in a static way.

Pascal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!