所以这是我的问题,我怎样才能使线程停止,我不是线程很精通,但我看了一些信息告诉我,这应该工作。我怎样才能让这个线程停止
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时,新**线程停止**。该代码适用于我。问题必须出现在此处未发布的代码中。 –