為什么用為什么用if((System.currenttime - time)<1000)而不用sleep(1000)?
5:17的時候為什么用為什么用if((System.currenttime - time)<1000)而不用sleep(1000)?因為sleep(1000)指定是1000毫秒,而if((System.currenttime - time)<1000)可以是大于1000的其他數?因為sleep()可能會造成線程阻塞?
5:17的時候為什么用為什么用if((System.currenttime - time)<1000)而不用sleep(1000)?因為sleep(1000)指定是1000毫秒,而if((System.currenttime - time)<1000)可以是大于1000的其他數?因為sleep()可能會造成線程阻塞?
2016-07-13
舉報
2016-07-13
調用sleep()阻塞當前線程,當其他線程調用interrupt()的時候,sleep()會發生InterriptedException()中斷異常,并清除中斷狀態。System.currenttime - time)<1000是if的判斷條件,當這個值小于1000時進入if()代碼塊執行程序。