Sleep method in java

The sleep() method of Thread class is used to sleep a thread for the specified amount of time.

Syntax of sleep() method in java

The Thread class provides two methods for sleeping a thread:

  1. public static void sleep(long miliseconds)throws InterruptedException
  2. public static void sleep(long miliseconds, int nanos)throws InterruptedException

Example of sleep method in java

Flash Soon


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.

Copyright 2017 Design& Development