1,休眠线程
-
Thread.sleep(毫秒,纳秒), 控制当前线程休眠若干毫秒
-
1秒= 1000毫秒
-
1秒 = 1000 * 1000 * 1000纳秒 1000000000
public class Demo3_Sleep {
public static void main(String[] args) throws InterruptedException {
//demo1();
new Thread() {
public void run() {
for(int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(getName() + "...aaaaaaaaaa");
}
}
}.start();
new Thread() {
public void run() {
for(int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(getName() + "...bb");
}
}
}.start();
}
public static void demo1() throws InterruptedException {
for(int i = 20; i >= 0; i--) {
Thread.sleep(1000);
System.out.println("倒计时第" +i + "秒");
}
}
}