java multithreading -sleep simulate network delay, the countdown

// sleep Analog Delay:

public class hh implements Runnable {

public static void main(String[]args) throws InterruptedException
{
    Date date=new Date(System.currentTimeMillis()+1000*10);//当前时间加10秒
    long endTime=date.getTime();
    while(true)
    {
        System.out.println(new SimpleDateFormat("mm:ss").format(date));//以分:秒的形式输出
        Thread.sleep(1000);
        date=new Date(date.getTime()-1000);
        if(endTime-1000*10>date.getTime())
        {
            break;
        }

    }

}
public static void test() throws InterruptedException
{
    int num=10;
    while(true)
    {
        Thread.sleep(1000);
        System.out.println(num--);
    }
}

}

Guess you like

Origin blog.51cto.com/14437184/2427791