所以我有两个文件,第一个是swing类,第二个是我的线程类。当我因为某种原因运行我的线程时,它不运行,我试着通过放置一些打印语句来查看我的程序是否会到达那里,但没有一个运行。程序没有执行线程
我的线程类
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class CheckFiles implements Runnable {
public void run() {
while (!UserInterface.stop) {
try {
String line;
BufferedReader b = new BufferedReader(new FileReader(UserInterface.location));
while((line = b.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) { System.out.println(e); }
}
}
}
在我的UserInterface I类通过执行以下操作
System.out.println(stop); //prints true
loadFile.setEnabled(false); //not important
status.setText("Checking Files"); //not important
stop = false;
System.out.println(stop); //prints false
new CheckFiles(); //start thread
启动方法本身就存在的东西是从运行停止我的线程还是我这样做错误?
有点提示:确保'UserInterface.stop'是挥发性的,因为你在两个不同的线程中使用一个变量而没有同步。 – Vertex