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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

最后的思考題

所以除了設(shè)置狀態(tài)標(biāo)志,還有什么退出線程的方法呢???

正在回答

5 回答

在catch中再次調(diào)用interrupt()就OK了

7 回復(fù) 有任何疑惑可以回復(fù)我~
#1

我是貓_夏 提問(wèn)者

非常感謝!
2018-07-18 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慘的一

想問(wèn)一下這個(gè)是什么原理
2018-09-24 回復(fù) 有任何疑惑可以回復(fù)我~
#3

霸氣小肆毛 回復(fù) 慘的一

當(dāng)重新調(diào)用子線程的interrupt()方法時(shí),也就是重新給子線程的中斷狀態(tài)設(shè)置為true,則子線程的isInterrupted()方法或者interrupted()方法能夠正確返回子線程的中斷狀態(tài)(為true),然后while循環(huán)中不滿足,就可以退出循環(huán),結(jié)束線程了
2019-03-30 回復(fù) 有任何疑惑可以回復(fù)我~

也可以在catch中寫(xiě)一個(gè) break;

1 回復(fù) 有任何疑惑可以回復(fù)我~

在catch中加入interruput()后,有點(diǎn)不太明白,退出是能退出,但是Thread running少打印了一次啊

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

我愛(ài)孫佳怡

剛才試了下,沒(méi)錯(cuò),沒(méi)少打印,自己看錯(cuò)了
2019-05-22 回復(fù) 有任何疑惑可以回復(fù)我~

package imooc.concurrent;


public class WrongWayStopThread extends Thread {

public static void main(String[] args) {


WrongWayStopThread thread = new WrongWayStopThread();

System.out.println("Staring thread...");

thread.start();


try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println("Interrupting thread...");

thread.interrupt();

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

thread.keepRunning=false;


System.out.println("Stopping application...");

}


public volatile boolean keepRunning = true;


public void run() {


while (keepRunning) {

System.out.println("Thread is running...");

long time = System.currentTimeMillis();

while (System.currentTimeMillis() - time < 1000) {


}


}

}

}


2 回復(fù) 有任何疑惑可以回復(fù)我~

還有就是用try{}catch{}把while循環(huán)包起來(lái)

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(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)