Sleep Function Example Java Program
Definition
Sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system.Syntax
Thread.sleep(Sleep_time);
Sleep Function Example Program
public class SleepFunctionDemo {
public static void main(String args[])
throws InterruptedException {
String[] str = {
"This is statement 1",
"This is statement 2",
"This is statement 3",
"This is statement 4"
};
for (int i = 0;i < str.length;i++) {
Thread.sleep(4000);
System.out.println(str[i]);
System.out.println("After 4 seconds....");
}
}
}
Sample Output
Output is: This is statement 1 After 4 seconds.... This is statement 2 After 4 seconds.... This is statement 3 After 4 seconds.... This is statement 4 After 4 seconds....
Miscellaneous Programs
- Super Keyword Example Java Program
- This Keyword Example Java Program
- Sleep Function Example Java Program
- IP Address Example Java Program
- Print Date Example Java Program
- Print Time Example Java Program
- Print Week Example Java Program
- User Defined Package Example Java Program
- Command Line Arguments Example Java Program
Read More Articles
- Multiple Inheritance Using Interface Example Java Program
- Single Inheritance Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Create Matrix Example Java Program
- Find all Substrings of a given string Example Java Program
- Sum Of Three Numbers Example Java Program
- Twin Prime Example Java Program
- Heap Sort Example Java Program
- Compile Time Polymorphism Example Java Program
