亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師,我的代碼為什么停不下來????

public?class?WrongExit?extends?Thread{
	public?void?run(){
		while(!this.isInterrupted()){
			System.out.println("Thread?is?continuing");
			long?time?=?System.currentTimeMillis();
			while((System.currentTimeMillis()-time<1000)){
			}
		}
	}
	public?static?void?main(String[]?args){
		WrongExit?WE?=?new?WrongExit();
		System.out.println("----------線程開始---------");
		WE.start();
		try?{
			Thread.sleep(3000);
		}?catch?(InterruptedException?e)?{
			//?TODO?自動生成的?catch?塊
			e.printStackTrace();
		}
		System.out.println("********3秒后終止線程********");
		Thread.interrupted();
		try?{
			Thread.sleep(3000);
		}?catch?(InterruptedException?e)?{
			//?TODO?自動生成的?catch?塊
			e.printStackTrace();
		}
		System.out.println("線程結束");
		}
}


正在回答

3 回答

用WE.interrupt()。?Thread.interrupted()錯了。

0 回復 有任何疑惑可以回復我~
#1

初級學習號

為什么錯了,Thread.interrupted()是不是中斷main主線程?
2015-06-25 回復 有任何疑惑可以回復我~
#2

Jimmy 回復 初級學習號

public static boolean interrupted():測試當前線程是否已經被中斷。該方法會清除線程的'中斷狀態'。 具體解釋可以查閱API文檔
2016-01-30 回復 有任何疑惑可以回復我~

變量首寫字母 建議小寫 駝峰式命名 ?用你的變量去interrupt,

Thread.interrupted()

進程的interrupt狀態被清除(cleard)而非被設置(set)。

0 回復 有任何疑惑可以回復我~

因為你定義的名字是WE

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

老師,我的代碼為什么停不下來?。??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號