Question

I would like to stop a thread in mid execution. From reading around, I am of the thought I will have to check a local variable to determine if the thread should continue or clean up and exit run(). Any ideas of cleanly implementing this?

Was it helpful?

Solution

Often a way to do this is create a boolean volatile member variable, perhaps called "stopThread". The thread periodically polls this variable to see if it should terminate.

OTHER TIPS

You could use the interrupt method. You could do some clean up before exiting the thread. A simple tutorial is here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top