This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use sleep without thread implementation  RSS feed

 
Sudhakar Veluru
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use sleep method in my application without using threads. is there any System.sleep() kind of thing??
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to do that?
Thread.sleep() is a static method, which sleeps the current thread. You do NOT need to create any thread.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use what Rathore has specified or you can try to get the current thread and use sleep if you want by
Thread.currentThread().sleep()

[This message has been edited by Rahul Mahindrakar (edited April 03, 2001).]
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With respect, we do NOT need to get reference to the current thread. That reference is meaningless because sleep is a static method, and it always sleeps the current thread only. sleep() can never affect any thread other than the current thread. We don't need reference to an instance of a class to invoke a static method of the class.
 
sandeep bagati
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sudhakar Veluru:
Can I use sleep method in my application without using threads. is there any System.sleep() kind of thing??

The basic concept of java is a thread is always running in your application program.So sleep without threads is meaningless.Sleep means to sleep a thread.And when u say Thread.sleep() in main() it is the main thread u are commanding to sleep.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Rathore you are right. I have gone through your earlier posts and I really appreciate the work you are doing here. Great going.

[This message has been edited by Rahul Mahindrakar (edited April 05, 2001).]
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Its my pleasure.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!