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