I just found an interesting situation. Suppose you have SwingWorker (I made it vaguely reminiscent of my own):
public class AddressTreeBuildingWorker extends SwingWorker<Void, NodePair> {
private DefaultTreeModel model;
public AddressTreeBuildingWorker(DefaultTreeModel model) {
}
@Override
protected Void doInBackground() {
}
@Override
protected void process(List<NodePair> chunks) {
for (NodePair pair : chunks) {
model.insertNodeInto(parent, child, parent.getChildCount());
}
}
private static class NodePair {
private final DefaultMutableTreeNode parent;
private final DefaultMutableTreeNode child;
private NodePair(DefaultMutableTreeNode parent, DefaultMutableTreeNode child) {
this.parent = parent;
this.child = child;
}
}
}
If the work performed in the background is significant, then everything works well - it is process()called with relatively small lists of objects, and everyone is happy.
The problem is that if the work done in the background is suddenly negligible for any reason, it process()gets a huge list of objects (for example, I saw 1,000,000), and by the time you process each object, you spent 20 seconds on the topic The "Event Manager" is exactly what SwingWorker designed to avoid.
, , SwingWorker - .
? , , , .