09_ Control Thread _ Thread sleeping sleep

Source: Internet
Author: User
Tags thread class

"Thread Sleep"

If you want the currently executing thread to pause for a while and go into a blocking state, you can do so by calling the static method sleep () method of the thread class.

There are two overloaded forms of the Sleep () method:

1.static void sleep (Long Millis): lets the currently executing thread pause for millis milliseconds and into a blocking state.

2.static void sleep (Long millis,int Nanos): This method is rarely used with nanoseconds.

After the current thread calls the sleep () method into a blocking state, the thread will not get an execution opportunity during its sleep period, even if there are no other executable threads in the system, and the thread in sleep () will not execute.

So the sleep () method is often used to pause the execution of a program.

"Sample Code"

Relatively simple, no demo

09_ Control Thread _ Thread sleeping sleep

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.