Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java Language
Expertise: Beginner
Apr 30, 1998

Java Pausing Abilities

Question:
I want to make my Java program pause for a specified amount of time, but I don't want to use a threading implementation. How can I do this?

Answer:
You really cannot avoid using threads in Java because the Java virtual machine automatically starts at least two separate threads. One thread is the low priority garbage collection thread and the other thread is the one that runs your main program. Graphical programs may automatically start a third or even additional threads to manage the GUI.

To pause your program for a specified amount of time, all you have to do is call the static method Thread.sleep(), which will suspend the calling thread for the specified number of milliseconds. To pause your program indefinitely, you must get a handle to the main thread and call its suspend() method. You can then resume the thread at a later time by calling the resume() method from a separate thread.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap