006 thread sleep

I. Overview

  There is a state in a thread when Time-wait. This state is often a thread waiting for time and then running. Common methods include sleep, wait, etc.

    Here we only talk about the hibernation case. 


2. Thread sleep

  There are two APIs we often use, one is the sleep() method in the Thread class, and the other is the sleep method of the TImeUnit class provided in versions after 5.

example: 

public static void main(String[] args) throws Exception {
        System.out.println ( " I 'm going to sleep using the sleep method.... " );
        Thread.sleep(3000);System.out 
        .println ( " I woke up... " );System.out 
        .println ( " I'm going to sleep using TimeUnit... " );
        TimeUnit.SECONDS.sleep(1);System.out 
        .println ( " I woke up... " );
    }

  The above example is relatively simple, we can easily accomplish this task...

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325386091&siteId=291194637