多執行緒,休眠執行緒。
阿新 • • 發佈:2020-07-20
public class Demo03 {
public static void main(String[] args) throws InterruptedException {
Test01();
new Thread(){
public void run(){
for(int i = 0;i<10;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {e.printStackTrace();
}
System.out.println(this.getName()+"aaaaa");
}
}
}.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(this.getName()+"bbbbbbb");
}
}
}.start();
}
public static void Test01() throws InterruptedException {
for(int i = 20; i >= 0; i--){Thread.sleep(1000);
System.out.println("倒計時第"+i+"秒");
}
}
}