java-How to delay few seconds

来源:互联网 发布:c语言输入函数 编辑:程序博客网 时间:2024/06/06 20:25

How to delay few seconds


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.lucas.test;import java.util.Date;public class TestSleep {public static void main(String[] args) {System.out.println("Testing..." + new Date());try {//sleep 5 secondsThread.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
原创粉丝点击