重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java多线程-sleep模拟网络延迟,倒计时

//sleep模拟网络延迟:

创新互联公司是一家专业提供伽师企业网站建设,专注与网站建设、成都网站制作HTML5、小程序制作等业务。10年已为伽师众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。

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--);
    }
}

}

标题名称:java多线程-sleep模拟网络延迟,倒计时
网页网址:http://cqcxhl.cn/article/jhcocs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP