I have code which I have been using for years and this morning I noticed property change isn't being called when the task is done. I've got the swing worker set up as an inner class and I put a break point on the String properyName = evt..... and it never hits the break point.
void loadData() {
work2 = new bkgdLoadData();
work2.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if( propertyName.equals("state")) {
SwingWorker.StateValue state = (SwingWorker.StateValue) evt.getNewValue();
if( state == SwingWorker.StateValue.DONE) {
work2 = null;
}
}
}
});
work2.execute();
}
You can see that I set the object work2 to null when the task is finished and now it is no longer being set to null. In the class I added a done routine which it hits when the doinbackground is finished. What is puzzling me is why the property change listener isn't triggered. Something must have changed without my noticing.
protected class bkgdLoadData extends SwingWorker<Integer, Object> {
@Override
protected Integer doInBackground() {
switch(bkgdMode) {
case 0:
doRead();
break;
case 1:
doWrite();
break;
case 2:
runRobot();
break;
}
return 0;
}
@Override
protected void done() {
int i=0;
i++;
}
}
The breakpoint at done is hit but no property change notice is delivered. (I put the done routine for the sole purpose of verifying that the swing worker knows that it is done.)
I looked at the documentation and I don't see that I have to manually fire off some sort of property change, so I am really, really stuck and would appreciate another pair of eyes to tell me what stupid mistake I am mistaking.
Thanks, Ilan