I have a thread containing a runnable.
I need this to loop infinitely unless cancelled by the user.
I have no idea how to go about this. All help is greatly appreciated.
Cheers.
I have a thread containing a runnable. I need this to loop infinitely unless
Share
Obviously you can easily add a loop inside of your
run()method:It’s always a good idea to check for thread interruption:
If you are asking about how you can cancel a thread operation from another thread (such as a UI thread) then you can do something like this:
We need to use a
volatile booleanso that changes to the field in one thread are seen in the other thread.