我很茫然,一个简单的swing worker的使用。我在 doInBackground() 中添加了一些简单的代码,但它没有执行,我没有收到异常。当我使用调试器时,他正在正常工作。))可能有人有这样的事情,或者告诉我如何缓存这个错误的想法,或者......对不起,代码很复杂。告诉我你需要更多的东西或评论。如果我删除“installer.setFPS(fPSCalculatorGhost.getFPS());”-string,一切都会好起来的。
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
}
});
public MainWindow() {
initComponents();
}
private void initComponents() {
InterfaceUpdateWorker interfaceUpdate = new InterfaceUpdateWorker(
new InterfaceInfoInstallerImpl());
interfaceUpdate.setCamera(gLEventListenerImpl.getCameraGhost());
interfaceUpdate.setfPSCalculatorGhost(gLEventListenerImpl.getFPSCalculatorGhost());
interfaceUpdate.execute();
}
@Override
protected Void doInBackground() throws InterruptedException {
while(true) {
installer.setFPS(fPSCalculatorGhost.getFPS());
installer.setCameraXPosition(
cameraGhost.getCameraXPosition());
installer.setCameraYPosition(
cameraGhost.getCameraYPosition());
installer.setCameraZPosition(
cameraGhost.getCameraZPosition());
Thread.sleep(200);
}
}
public final class FPSCalculatorGhost {
private FPSCalculatorGhost() {
}
public float getFPS() {
return fpsTask.getAvrfps();
}
}
public float getAvrfps() {
synchronized (this) {
return avrfps;
}
}
一切都围绕着 fpsTask-object。它由 interfaceUpdate-thread(或应用程序工作线程)使用,并由初始化它的其他线程使用。结果:1)。fpsTask-object 在一个线程中初始化 2)。fpsTask-object 给另一个线程赋值。
当我从 FPSCalculatorGhost 最终制作 fpsTask 时,它开始工作。