I have an application that I'm trying to restructure to use the MVC architecture. The GUI kicks off several long running function calls that would block the interface if I don't detach them from the GUI thread.
Now I was wondering whether wrapping the objects of the controller that have such long running functions into another version that just detaches the current call to a thread pool would be a good idea? Is there any pattern for this sort of problem?
EDIT Maybe I should provide a sample. Currently my code is littered with the following:
env.getScheduledExecutor().execute(new Runnable() {
public void run() {
backend.someLongRunningMethod();
}
});
Now I' wondering whether I should wrap the Backend
into something like a BackendFacade
class that will just wrap any function call into a runnable and schedule it to the executor.
It is worth noticing that most times the methods return void
or I don't care anyway. In the rare cases that I need to get the value back I'll just use Future
. It should not really be a huge change since I already decouple threads at some point but I'd like to consolidate how it is done across the whole project.