所以這是我的問題,我怎樣才能使線程停止,我不是線程很精通,但我看了一些信息告訴我,這應該工作。我怎樣才能讓這個線程停止
public class testestes {
static volatile boolean key;
public static void main (String []args)
{
key=true;
Thread thread=new Thread(new Runnable()
{
public void run()
{
while(key)
{
System.out.println("running");
}
}
});
thread.start();
key=false;
}
}
我試過你的代碼,它停下來。 –
我也不明白,一旦調用'run()'變爲'start()',新線程運行,當鍵設置爲false時,新**線程停止**。該代碼適用於我。問題必須出現在此處未發佈的代碼中。 –