当前正在执行的线程休眠(暂时停止执行)指定的毫秒数,具体取决于系统计时器和调度程序的精度和准确性。 该线程不会失去任何监视器的所有权。
代码如下:
public class Sleep {
public static void main(String[] args)throws InterruptedException {
new Thread( ){
public void run(){
try {
Thread.sleep(1000 );
}catch (InterruptedException e) {
e.printStackTrace();
}
for (int i=0;i<10;i++){
System.out.println("蒙奇D天鸿");
}
}
}.start();
new Thread( ){
public void run(){
try {
Thread.sleep(500);
}catch (InterruptedException e) {
e.printStackTrace();
}
for (int i=0;i<10;i++){
System.out.println("海贼王");
}
}
}.start();
}
}