Sleep method in javaThe sleep() method of Thread class is used to sleep a thread for the specified amount of time. Syntax of sleep() method in javaThe Thread class provides two methods for sleeping a thread:
Example of sleep method in javaOutput: 1 1 2 2 3 3 4 4 As you know well that at a time only one thread is executed. If you sleep a thread for the specified time,the thread shedular picks up another thread and so on. Next TopicCan we start a Thread Twice
|