- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sleeping for a while in Java
You can sleep for any period of time from one millisecond up to the lifetime of your computer. For example, the following program would sleep for 3 seconds −
Example
import java.util.*; public class SleepDemo { public static void main(String args[]) { try { System.out.println(new Date( ) + "
"); Thread.sleep(5*60*10); System.out.println(new Date( ) + "
"); } catch (Exception e) { System.out.println("Got an exception!"); } } }
This will produce the following result −
Output
Sun May 03 18:04:41 GMT 2009 Sun May 03 18:04:51 GMT 2009
Advertisements