使用new關鍵字創建線程,線程處於新建狀態。注意僅僅可對新建狀態的線程調用start(),並只能調用一次。
如果需要馬上調用子線程,可使用Thread.sleep(1)來使主線程睡眠1ms。
採用Thread.currentThread()獲取當前線程
採用System.out.println(Thread.currentThread().getName()+" "+Thread.currentThread().isAlive());輸出當前線程狀態是否活着。
使用new關鍵字創建線程,線程處於新建狀態。注意僅僅可對新建狀態的線程調用start(),並只能調用一次。
如果需要馬上調用子線程,可使用Thread.sleep(1)來使主線程睡眠1ms。
採用Thread.currentThread()獲取當前線程
採用System.out.println(Thread.currentThread().getName()+" "+Thread.currentThread().isAlive());輸出當前線程狀態是否活着。