我在Netbeans工作(不确定是否是一个因素)。
我只是想在后台运行一个简单的SwingWorker。我调用“ doInBackground()”,但调用线程仍处于暂停状态,直到工作人员完成为止。
即使是陌生人,当我从后台工作内部调用Thread.currentThread时,它也告诉我我正在处理事件调度线程(后台工作人员正在前台工作?)。
private void startButtonmouseReleased(java.awt.event.MouseEvent evt) {
if(startButton.isEnabled()) {
StartingWorker worker = new StartingWorker();
worker.doInBackground();
}
}
private class StartingWorker extends SwingWorker<Void,Void> {
public StartingWorker() {
}
@Override
public Void doInBackground() {
startOperation();
return null;
}
@Override
protected void done() {
}
}
private void startOperation() {
//When I call currentThread(),it says that this is the Even Dispatch Thread
//even though this message is being called from a SwingWorker.
Thread thread = Thread.currentThread();
try {
session.populate(reporter);
Runnable run = new Runnable() {
public void run() {
callObservers(true);
}
};
SwingUtilities.invokeAndWait(run);
}
catch(Exception e) {
unlock();
Dialogs.showErrorDialog(this.getParent());
}
}