為什么用為什么用if((System.currenttime - time)<1000)而不用sleep(1000)?
5:17的時(shí)候?yàn)槭裁从脼槭裁从胕f((System.currenttime - time)<1000)而不用sleep(1000)?因?yàn)閟leep(1000)指定是1000毫秒,而if((System.currenttime - time)<1000)可以是大于1000的其他數(shù)?因?yàn)閟leep()可能會造成線程阻塞?
5:17的時(shí)候?yàn)槭裁从脼槭裁从胕f((System.currenttime - time)<1000)而不用sleep(1000)?因?yàn)閟leep(1000)指定是1000毫秒,而if((System.currenttime - time)<1000)可以是大于1000的其他數(shù)?因?yàn)閟leep()可能會造成線程阻塞?
2016-07-13
舉報(bào)
2016-07-13
調(diào)用sleep()阻塞當(dāng)前線程,當(dāng)其他線程調(diào)用interrupt()的時(shí)候,sleep()會發(fā)生InterriptedException()中斷異常,并清除中斷狀態(tài)。System.currenttime - time)<1000是if的判斷條件,當(dāng)這個(gè)值小于1000時(shí)進(jìn)入if()代碼塊執(zhí)行程序。