Thread.sleep
程序员文章站
2022-07-14 16:15:49
...
Thread.sleep 在指定的毫秒数内让当前正在执行的线程休眠(暂停执行),就是线程睡眠一定的时间,也就是交出cpu一段时间,根据参数来决定暂停时间.让给等待序列中的下一个线程.Thread.sleep抛出InterruptedException. This is an exception that sleep throws when another thread interrupts the current thread while sleep is active。
以下代码来自java tutorials
以下代码来自java tutorials
public class SleepMessages {
public static void main(String args[]) throws InterruptedException {
String importantInfo[] = { "Mares eat oats", "Does eat oats",
"Little lambs eat ivy", "A kid will eat ivy too" };
for (int i = 0; i < importantInfo.length; i++) {
Thread.sleep(4000);
System.out.println(importantInfo[i]);
}
}
}
上一篇: c# Thread.Sleep与Task.Delay 区别
下一篇: 均值滤波代码 C代码