try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
public class TestSleep {
public static void main(String[] args) {
MyThread2 t1 = new MyThread2("TestSleep");
t1.start();
for(int i=0 ; i <10; i++)
System.out.println("I am Main Thread");
}
}
class MyThread2 extends Thread {
MyThread2(String s) {
super(s);
}
public void run() {
for(int i = 1; i <= 10; i++) {
System.out.println(“I am “+getName());
try {
sleep(1000); //暫停,每一秒輸出一次
}catch (InterruptedException e) {
return;
}
}
}
}
public class MyThread extends Thread {
public void run() {
for (int i = 0; i < 100; i++) {
if ((i) % 10 == 0) {
System.out.println(“——-” + i);
}
System.out.print(i);
try {
Thread.sleep(1000);
System.out.print(” 線程睡眠1秒!\n”);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new MyThread().start();
}
}
PHP sleep() 函數(shù)#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int main()
{
int a = 1;
while (a)
{
printf("Welcome to songjiahao's blog\n");
Sleep(1000);
}
system("pause");
return 0;
}
sleep(seconds)
參數(shù) | 描述 |
---|---|
seconds | 必需。以秒計(jì)的暫停時(shí)間。 |
若成功,返回 0,否則返回 false。
如果指定的描述 seconds 是負(fù)數(shù),該函數(shù)將生成一個(gè) E_WARNING。
例子輸出:<?php
echo date('h:i:s') . "<br />";
//暫停 10 秒
sleep(10);
//重新開始
echo date('h:i:s');
?>
如對本文有疑問,請?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇