APIs to do some background processing (in a loop), and it's working well, but now I'd like to add an ability to gracefully cancel/abort (early-exit) from the background loop.
What's the correct way to implement this? Is there some flag I can check for in my background loop that is set when
requestTermination
has been called?
I understand there are restrictions on sharing state, so for example I get an
IllegalStateException
if I try to pass in a
BooleanVar
into my worker args.
o
olonho
09/18/2017, 9:21 PM
IllegalState is triggered by the case, when variable is still referenced by original owner, maybe deepCopy would help. In your case, maybe just sending an explicit termination request with custom message would help.
a
andreasmattsson
09/19/2017, 7:41 AM
Yeah, my mistake. You are right in this case it wasn't the termination flag I passed that was a problem but rather a string variable I passed.
E.g. passing it like this was not working: