I have a certain function that has exponential run time and should be executed in the background.
If a user does not wish to wait for the result, he should be able to cancel the computation with a button press. I don't want to keep anything from this computation.
Since I couldn't find a good way to cancel the computation, I embedded the algorithm into a class
extending Thread
and also have checks for the interrupt
flag in the algorithm.
In my opinion this destroys the "beauty" of the algorithm since it is now only available with this Thread class.
I haven't done much with Futures
or Actors
yet. Is it possible to use them for this kind of problem? How would you approach it? Thanks in advance.