Java – How to delay few seconds

来源:互联网 发布:网络协议分析器 编辑:程序博客网 时间:2024/06/07 02:37

In Java, you can use Thread.sleep(miliseconds) to make the current executing Java program to sleep or delay few seconds.

TestSleep.java

package com.mkyong.test;import java.util.Date;public class TestSleep {    public static void main(String[] args) {        System.out.println("Testing..." + new Date());        try {            //sleep 5 seconds            Thread.sleep(5000);            System.out.println("Testing..." + new Date());        } catch (InterruptedException e) {            e.printStackTrace();        }    }}

Output

Testing...Tue Sep 22 17:26:51 SGT 2015Testing...Tue Sep 22 17:26:56 SGT 2015
0 0
原创粉丝点击