第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我想請(qǐng)問(wèn)關(guān)于interrupt()

我想請(qǐng)問(wèn)關(guān)于interrupt()

hy_wang 2017-08-15 20:00:33
我想請(qǐng)問(wèn)關(guān)于interrupt()這個(gè)方法調(diào)用什么時(shí)候才可以?huà)伋霎惓??老師講解是在線程被阻塞的時(shí)候調(diào)用會(huì)拋出異常。package?one; public?class?newnew?extends?Thread?{ ?public?void?run(){ ????????? ????????System.out.println("線程正在運(yùn)行"); ????????long?time?=?System.currentTimeMillis(); ????????while((System.currentTimeMillis()-time)<1000){} ????} ????? ????public?static?void?main(String[]?args)?{ ????????? ???? newnew?wwst?=?new?newnew(); ????????System.out.println("啟動(dòng)線程?"); ????????wwst.start(); ????????? ????????try?{ ????????????sleep(3000); ????????}?catch?(InterruptedException?e)?{ ????????????e.printStackTrace(); ????????} ????????? ????????System.out.println("中斷線程"); ????????wwst.interrupt(); ????????? ????????try?{ ????????????sleep(3000); ????????}?catch?(InterruptedException?e)?{ ????????????e.printStackTrace(); ????????} ????????System.out.println("線程結(jié)束了"); ????????? } } 可是請(qǐng)問(wèn)關(guān)于這段代碼?我在調(diào)用wwst.interrupt();的時(shí)候上邊明明有 ?sleep(3000);??運(yùn)行的時(shí)候卻沒(méi)有拋出異常 ?而如果我?在run()方法中?假如sleep()方法就會(huì)拋出異常 ?請(qǐng)教這是為什么?想不通
查看完整描述

3 回答

?
用戶(hù)1122125

TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超0個(gè)贊

你在 run 里執(zhí)行 sleep 是停的run 方法執(zhí)行的那個(gè)線程

查看完整回答
反對(duì) 回復(fù) 2017-08-16
?
用戶(hù)1122125

TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超0個(gè)贊

你直接調(diào)用 sleep? 是把主線程聽(tīng)了3秒…

查看完整回答
反對(duì) 回復(fù) 2017-08-16
  • 3 回答
  • 0 關(guān)注
  • 1448 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)