in Technology by

Describe the purpose and working of sleep() method.

1 Answer

0 votes
by

The sleep() method in java is used to block a thread for a particular time, which means it pause the execution of a thread for a specific time. There are two methods of doing so.

Syntax:

  • public static void sleep(long milliseconds)throws InterruptedException
  • public static void sleep(long milliseconds, int nanos)throws InterruptedException

Working of sleep() method

When we call the sleep() method, it pauses the execution of the current thread for the given time and gives priority to another thread(if available). Moreover, when the waiting time completed then again previous thread changes its state from waiting to runnable and comes in running state, and the whole process works so on till the execution doesn't complete.

Related questions

0 votes
    Which of these method is used to tell the calling thread to give up a monitor and go to sleep until ... division Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What is sleep mode in android?...
asked Jan 14, 2021 in Technology by JackTerrance
0 votes
    i am in hurry , i want to sleep early; but i have a test for tomorrow, i have not study what can ido Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    He could not sleep because (i) there was an animal outside (ii) he thought savages had com (iii) his bed was uncoinfortable Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Can the users simply switch to a previous version while working on a repository in SVN? If so, what is the simplest method for this according to you?...
asked Feb 18, 2021 in Technology by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Which method to use while working with XML fragments, instead of XML()? (a) XMLInterface() (b) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    What is the purpose of wait() method in Java?...
asked Jan 19, 2021 in Technology by JackTerrance
0 votes
    Consider that you have to move data over long distances using the internet across countries or continents to your Amazon ... Which method or service will you use for this purpose?...
asked Dec 3, 2020 in Technology by Editorial Staff
0 votes
    What should be the purpose of HEAD method of RESTful web services?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    What should be the purpose of OPTIONS method of RESTful web services?...
asked Nov 7, 2020 in Technology by JackTerrance
...