The question and code details are a bit vague and that makes it hard to understand very specifically what you are asking for and need help with but I'll try to infer.
When an instance of your class Scripter
is started (on Java thread), it will execute the code in the run()
method (this is where the 'work' takes place) when the thread is allocated CPU resources. It runs like any other method and if it returns or completes, then the thread is finished and it will be cleaned up.
Thus if the following code:
if (stopscript)
return;
is called in run()
method, then if that condition is true, the return
terminates the run()
method and the thread can terminate and clean up safely (presumably, correctness depends on what your program needs to do and how you are handling concurrency).
If you just call stop()
on the thread running the instance of Scripter
, it stops it in whatever state it is in i.e. it could be half-way through a calculation or may not properly clean up its resources usage as detailed in the Javadoc you read.
It essentially makes your program less predictable because the thread isn't allowed to terminate gracefully and that is (can be) problematic.