0
我已經嘗試了三種方法,但我無法獲得任何工作。我從這個帖子的頂部答案中拿了很多我的代碼How to know if other threads have finished?我在那個列表中緊跟第5條。這是我的問題:從我的主線程中,我需要能夠檢測按下按鈕時輔助線程是否正在運行。檢測一個線程是否正在運行java fx
1日法
NotifyThread task = null;
@FXML
private void handleButtonPress(ActionEvent event){
if (thread == null){
NotifyThread thread = new Thread2(1,0);
}
else{
//task is already running
thread.end()
}
與上面的代碼的問題是,線程總是空。而不會終止現有線程的它創建另一個運行旁邊(不好)
第二個方法
if (thread.isAlive())
第三屆方法
if(thread.getState.equals(RUNNABLE))
這兩種方法給我運行時異常
好的。我剛剛離開我發佈的鏈接,他說NotifyThread thread1 = new OneOfYourThreads(); –