How do you get the SwingWorker that code is currently running in? You can use Thread.currentThread() to get the Thread instance, but I need the SwingWorker instance.
Code from the comments
private static void loadFeaturesForSym(final SeqSymmetry optimized_sym,
final GenericFeature feature)
throws OutOfMemoryError {
final CThreadWorker<Boolean, Object> worker =
new CThreadWorker<Boolean, Object>("Loading feature " + feature.featureName) {
@Override
protected Boolean runInBackground() {
try {
return loadFeaturesForSym(feature, optimized_sym);
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
};
ThreadHandler.getThreadHandler().execute(feature, worker);
}
}
I recommend you create a model object to which the SwingWorker can listen and send those updates out the publish and process methods. Your other objects should not know about SwingWorker, they should just know about their own progress and publish that out to whoever wants to listen. It’s called decoupling. Here’s one idea for doing it, which uses something that approaches MVC. I have not compiled this code, but it helps explain what I am talking about.